When 2 events are simultaneously triggered in JavaScript, the javascript engine use a single queue (first procedure in, first out), or the engine internally create independent threads? and if is the second option(there could be concurrency problems due to this).
Thanks beforehand, for your time :)
asked Sep 12, 2012 at 1:39
Aronis Mariano
2,4413 gold badges23 silver badges19 bronze badges
-
I thought all event driven engines were single thread. The other option is thread blocking right? I only know php / js, so that could be wrong.Chris– Chris2012年09月12日 01:45:52 +00:00Commented Sep 12, 2012 at 1:45
1 Answer 1
JavaScript is single-threaded. Two events cannot occur completely simultaneously, so they are handled in the order in which they arrive.
answered Sep 12, 2012 at 1:40
Niet the Dark Absol
326k86 gold badges480 silver badges604 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Niet the Dark Absol
I think so, but I think that's the only exception.
Subtubes
Yes WebWorkers get their own thread but when they are done the results are fed back to the queue which forces the output to be executed on the main thread once the stack has cleared. They are good for really heavy lifting like processing image data.
lang-js