why Javascript SetTimeout() is not multithreaded

前端 未结 8 499
生来不讨喜
生来不讨喜 2020-12-20 13:49

I have a test:

Html:

Empty
Empty

js:

var s1 =         


        
8条回答
  •  执笔经年
    2020-12-20 14:41

    Javascript is not multithreaded nor non-multithreaded per se. However, the specific implementations of Javascript that currently are implemented in major browsers mostly ARE single-threaded.

    In addition, for proper multithreading, the language needs to have facilities for shared memory, locks, semaphors and other concurrent programming tools, which JavaScript as is currently defined does not have (for example, there is no way to describe how concurrent JS threads would control who gets to update DOM objects that are of course, shared since there's only one DOM in a window).

    There are attempts to make JS more parallelized - look at web workers, Intel's River Trail, Google's HTML5 work and more.

提交回复
热议问题