javascript - Ask a process-related question, js?
仅有的幸福
仅有的幸福 2017-06-12 09:23:56
0
4
583

Declare an empty array, open four processes and push values ​​into the array at the same time. What is the order in which the pushes are entered?

仅有的幸福
仅有的幸福

reply all(4)
小葫芦

I have never heard of the saying that js has multiple processes, and it is impossible to modify an array at the same time. You can post the code for other experts to take a look

三叔

You should write it in NodeJS

学霸

A simple experiment is as follows. When multiple processes (tasks) operate, the value of the array depends on the last process. I use 2 setTimeout and 1
setInterval to simultaneously operate an array, and push into three values ​​​​1, 2, and 3 respectively. The final result is:

[1, 2, 3, 3, 1, 1, 3, 1, 1, 3]

There is a clear explanation in Ruan Yifeng’s article: Single thread means that all tasks need to be queued, and the next task will not be executed until the previous task is completed. If the previous task takes a long time, the next task will have to wait. ;View original text

typecho

Just test it and you will know. Print this array every time the push is successful

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!