简体   繁体   English

如何在NodeJS中控制对变量的并发访问?

[英]How to control concurrency access on a variable in NodeJS?

For example: 例如:

var i = 0;
while(true)
  http.request('a url', callback_f);

function **callback_f**(){
  **i++**;
}

In my simple imaginary example, some request might try to increase i's value in the same time, How can I write a code which is thread safe in NodeJS? 在我简单的虚构示例中,某些请求可能会尝试同时增加我的价值,如何编写在NodeJS中线程安全的代码?

You do not have to worry about threads in Node.js. 您不必担心Node.js中的线程。 Node.js handles all calls within a single threaded environment. Node.js处理单个线程环境中的所有调用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM