"call stack" 和 "task queue" 之间的区别

Difference between "call stack" and "task queue"

我是一名开发人员,很难区分术语 Call StackTask Queue。有谁能帮我解释一下区别吗?

提前致谢。

A job queue (sometimes batch queue), is a data structure maintained by job scheduler software containing jobs to run.

https://en.wikipedia.org/wiki/Job_queue

A call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, control stack, run-time stack, or machine stack, and is often shortened to just "the stack".

https://en.wikipedia.org/wiki/Call_stack

简而言之,作业队列是要做的事情的队列(通常是持久存储的),调用堆栈是例程堆栈。

作业将分配有变量,调用堆栈将是抽象实现。

因此作业可以 "call" 来自调用堆栈的方法。

编辑: 可能会有一份工作清单;

  • 将 foo.jpg 调整为 100x100
  • 将 bar.png 调整为 100x100

并且每个作业都会 运行 多次调用堆栈;

第一份工作

  • 复制foo.jpg到内存
  • 将其调整为 100x100
  • 将调整后的 foo.jpg 存储在拇指文件夹中

第二份工作:

  • 复制bar.png到内存
  • 将其调整为 100x100
  • 将调整后的 foo.jpg 存储在拇指文件夹中

例如。

在JavaScript中有一个叫做timeout的函数。当您在 "call stack" 上调用函数超时时,它将在 "job queue" 中注册。它不会立即触发,但会在到达时间后触发。

timeout(function(){
    console.log("one");
}, 100);

console.log("two");

在调用栈中,console.log("one")先触发,但在作业队列中,结果显示在two之后。