search

Home  >  Q&A  >  body text

javascript - Ask a process-related question, js?

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?

仅有的幸福仅有的幸福2816 days ago655

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-06-12 09:25:56

    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

    reply
    0
  • 三叔

    三叔2017-06-12 09:25:56

    You should write it in NodeJS

    reply
    0
  • 欧阳克

    欧阳克2017-06-12 09:25:56

    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

    reply
    0
  • typecho

    typecho2017-06-12 09:25:56

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

    reply
    0
  • Cancelreply