I know, I know -- it isn't possible presently but my question is this:

Would it be possible to write a browser plug in for the major browsers that enables true, multi-threaded JavaScript?

It just seems like this would be possible and, if so, it would take the web (not to mention JavaScript) to new heights.

  • Newer visitors might want to consider googling "Javascript Web Workers" for discussion on modern implementations of multithreading in a javascript context. Yes, despite the answers below, now it's a thing! :-D – tu-Reinstate Monica-dor duh Aug 18 '16 at 1:48

The DOM and it's various APIs are NOT thread-safe. No browser plug-in will be able to make them thread-safe without essentially breaking the pure multi-threading.

Some DOM functions like document.getElementsByTagName() are inherently thread-unsafe because they return a dynamic collection that automatically changes as the DOM is changed. You couldn't even safely loop through the results of that collection if some other thread might be changing the DOM at the same time. A new DOM API could be written with thread safety in mind, but that would be a major undertaking and some existing behaviors would have to be discontinued.

Plus, modern browsers already have web workers which allow pure javascript multi-threading (without DOM access in the threads) so you'd have to describe what more beyond web workers that doesn't require DOM access you are interested in implementing.


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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.