admin管理员组文章数量:1391944
If I have javascript code running which for example performs some action on a timer and this code is embedded in web pages in tab 1 and tab 2 of a web browser, then could the client code run concurrently? Or is javascript client code always run in only a single browser thread?
Alternatively, if there is a frameset with a parent and child frames, then could javascript code run concurrently in this situation?
Is there a standard specified model or is it browser dependent?
My main target environment is IE9 so would be interested to know what happens there.
EDIT I am not looking for threading support or how to do threading in javascript. I personally don't see the need. It also makes life more plicated. I just want to know if I need to worry about it, and if so on which browsers.
If I have javascript code running which for example performs some action on a timer and this code is embedded in web pages in tab 1 and tab 2 of a web browser, then could the client code run concurrently? Or is javascript client code always run in only a single browser thread?
Alternatively, if there is a frameset with a parent and child frames, then could javascript code run concurrently in this situation?
Is there a standard specified model or is it browser dependent?
My main target environment is IE9 so would be interested to know what happens there.
EDIT I am not looking for threading support or how to do threading in javascript. I personally don't see the need. It also makes life more plicated. I just want to know if I need to worry about it, and if so on which browsers.
Share Improve this question edited Mar 24, 2013 at 11:52 Angus Comber asked Mar 24, 2013 at 11:39 Angus ComberAngus Comber 9,72814 gold badges64 silver badges114 bronze badges 1- Two tabs are pletely unrelated; there is no standard for. Chrome for example even runs each of them in a different process, while Opera is known to do everything in only one thread. – Bergi Commented Mar 24, 2013 at 14:40
1 Answer
Reset to default 7For a single JavaScript "object space" (a single page in a browser or an interpreter instance in node.js) there is at most one thread running. In fact speaking about threads in the context of JavaScript is not meaningful. The JS execution model is event-loop and callback based.
Different frames can never run concurrently because they can access the DOM (and by extension arbitrary objects) of each other. This would make threading unsafe.
With web workers there is no direct access to any data structure across the worker boundary so threading is not observable and can safely occur. The only munication here is through message passing.
本文标签: multithreadingJavascriptweb browser threading modelStack Overflow
版权声明:本文标题:multithreading - Javascriptweb browser threading model - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744669564a2618742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论