简体   繁体   English

“调用堆栈”和“任务队列”之间的区别

[英]Difference between “call stack” and “task queue”

I'm a developer having difficulties in differentiating between the terms Call Stack and Task Queue . 我是一名开发人员,难以区分术语“ 调用堆栈”和“ 任务队列” Is there anyone who can help me explain the difference? 有谁可以帮助我解释其中的区别?

Thanks in advance. 提前致谢。

eg. 例如。

in JavaScript there is function called timeout. 在JavaScript中,有一个称为超时的函数。 when you call the function timeout on the "call stack" it would register in "job queue". 当您在“调用堆栈”上调用函数超时时,它将在“作业队列”中注册。 It won't fire immediately, but will be triggered once the time is reached. 它不会立即触发,但一旦到达时间就会触发。

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

console.log("two");

in call stack, console.log("one") is triggered first, but in job queue, the result will display after two . 在调用堆栈中,首先触发console.log("one") ,但在作业队列中,结果将在two之后显示。

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 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 https://en.wikipedia.org/wiki/Call_stack

So in short, a job queue is a queue of things to do (usually stored persistant) and a call stack is a stack of routines. 简而言之,作业队列是要做的事情(通常存储的持久性)队列,而调用堆栈是例程的堆栈。

A job would have variables assigned to it, and a call stack would be the abstract implementation. 作业将分配有变量,调用堆栈将是抽象实现。

So a job could "call" a method from a call stack. 因此,作业可以从调用堆栈中“调用”方法。

EDIT: There could be a list of jobs; 编辑:可能会有一份工作清单;

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

and each job would run a call stack multiple times; 每个作业将多次运行调用堆栈;

First job 第一份工作

  • Copy foo.jpg into memory 将foo.jpg复制到内存中
  • Resize it to be 100x100 调整大小为100x100
  • Store the resized foo.jpg in the thumbs folder 将调整大小的foo.jpg存储在thumbs文件夹中

Second job: 第二份工作:

  • Copy bar.png into memory 将bar.png复制到内存中
  • Resize it to be 100x100 调整大小为100x100
  • Store the resized foo.jpg in the thumbs folder 将调整大小的foo.jpg存储在thumbs文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 事件队列和任务队列之间有什么区别吗? - Is there any difference between event queue and task queue? 浏览器中的事件循环和任务队列之间有区别吗? - Is there a difference between event loop and task queue in browsers? 堆栈和调用堆栈有什么区别 - What is the difference between stack and call stack 底层承诺(调用堆栈,Web API,任务队列) - Promises under the hood (call stack, Web API, task queue) 在javascript运行时中,堆栈的“框架”与队列的“消息”之间有什么区别? - In javascript runtime, what is the difference between a “frame” of the stack and a “message” of the queue? JS递归超出最大调用堆栈大小:2个函数之间的差异 - JS Recursion Maximum call stack size exceeded: difference between 2 functions Promise.prototype.then 链在以下方面会发生什么:调用堆栈、WebAPI 部分和微任务队列? - What happens with a Promise.prototype.then chain with regards to the: call-stack, WebAPI section and micro-task queue? 回调队列和事件队列有什么区别? - What is the difference between callback queue and event queue? .queue()和jquery.queue()之间的区别 - Difference between .queue() and jquery.queue() 了解 javascript 中的事件队列和调用堆栈 - Understanding Event Queue and Call stack in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM