JavaScript multithreading

后端 未结 5 1767
不知归路
不知归路 2020-12-02 20:44

I\'m working on comparison for several different methods of implementing (real or fake) multithreading in JavaScript. As far as I know only webworkers and Google Gears Worke

5条回答
  •  失恋的感觉
    2020-12-02 21:00

    Web Workers. They’re a W3C standard (well, a working draft at the moment) for exactly this, and require no plugins:

    This specification defines an API that allows Web application authors to spawn background workers running scripts in parallel to their main page.

    The specification also discusses spreading workers across multiple cores, for true concurrency (this is handled invisibly by the browser’s JavaScript engine):

    With multicore CPUs becoming prevalent, one way to obtain better performance is to split computationally expensive tasks amongst multiple workers. In [one] example, a computationally expensive task that is to be performed for every number from 1 to 10,000,000 is farmed out to ten subworkers.

    yield() and setInterval() only schedule things to happen later, they don’t run concurrently with anything else.

提交回复
热议问题