Brendan Eich has voiced his opposition to multi-threading in JavaScript several times:
So my default answer to questions such as the one I got at last May’s Ajax Experience, “When will you add threads to JavaScript?” is: “over your dead body!” (source)
And he goes on to list a few reasons why.
It's not just the DOM that's not thread-safe, the language itself does not lend itself to graceful multithreading. One of the big problems facing JavaScript is the highly flexible and dynamic type system. Since almost everything can be modified and redefined at run time, what happens to when the programmer modifies the body of Object.prototype.toString
method while another thread is actually calling Object.prototype.toString
? Or more generally, any method? The only safe way to handle this would be to synchronize any operations modifying the any method on any object -- since this a fairly common task in JavaScript, you would essentially revert it back to a single-threaded language again.
Web workers are able to get around this issue by ensuring that that the worker scripts do not share the same memory space as the main thread, so modifying objects in the work cannot interrupt or corrupt the operation of the main thread.