Monday, February 13, 2012

concurrency - Is javascript guaranteed to be single-threaded? - Stack Overflow

concurrency - Is javascript guaranteed to be single-threaded? - Stack Overflow: "JavaScript is usually considered to have a single thread of execution visible to scripts(*), so that when your inline script, event listener or timeout is entered, you remain completely in control until you return from the end of your block or function.

(*: ignoring the question of whether browsers really implement their JS engines using one OS-thread, or whether other limited threads-of-execution are introduced by WebWorkers.)

However, in reality this isn't quite true, in sneaky nasty ways.

The most common case is immediate events. Browsers will fire these right away when your code does something to cause them:"

'via Blog this'