Node.js的是否实际使用多线程下? [英] Does Node.js actually use multiple threads underneath?

查看:125
本文介绍了Node.js的是否实际使用多线程下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有的文学我读过关于node.js的我还是回来的问题,确实Node.js的本身充分利用多线程的引擎盖下?我想答案是肯定的,因为如果我们用简单的非同步文件读取例如有些事情必须做的工作,以读取该文件,但如果节点的主事件循环没有处理这项工作不是必须的意思是应该有一个POSIX线程运行的地方,开出文件读出的护理,然后在完成发出呼叫回事件循环被执行。所以,当我们说的Node.js在一个线程中运行我们实际上指的Node.js的事件循环只有一个线程?还是我失去了一些东西在这里......

After all the literature i've read on node.js I still come back to the question, does node.js itself make use of multiple threads under the hood? I think the answer is yes because if we use the simple asynch file read example something has to be doing the work to read the file but if the main event loop of node is not processing this work than that must mean there should be a POSIX thread running somewhere that takes care of the file reading and then upon completion places the call back in the event loop to be executed. So when we say Node.js runs in one thread do we actually mean that the event loop of node.js is only one thread? Or am i missing something here.....

推荐答案

要在node.js的JavaScript程序,的只有一个线程

To a Javascript program on node.js, there is only one thread.

如果你正在寻找技术性问题,Node.js的是免费使用的线程,如果底层操作系统需要它来解决异步I / O。

If you're looking for technicalities, node.js is free to use threads to solve asynchronous I/O if the underlying operating system requires it.

重要的是永远不要打破了只有一个线程抽象的JavaScript程序。如果有多个线程,所有他们能做的就是排队工作的JavaScript程序的主线程,他们永远不能执行任何JavaScript code自己。

The important thing is to never break the "there is only one thread" abstraction to the Javascript program. If there are more threads, all they can do is queue up work for the main thread in the Javascript program, they can never execute any Javascript code themselves.

这篇关于Node.js的是否实际使用多线程下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆