0

I'm wondering why JS hasn't evolved into a language that supports multithreading. I understand that we have the event loop model as the model of concurrency execution in the JS ecosystem. I realize this helps execute blocking tasks in a nonblocking way by essentially queuing up these tasks before invoking on the call stack. My question is mainly why don't we want multithreading in javascript? Is the issue mainly due to race conditions happening on the DOM and ruining the rendering on the page? I know that Node is more performant than Nginx (right?) due to the single threaded architecture for all requests, but just missing the why in all this?

John Lippson
  • 1,269
  • 5
  • 17
  • 36
  • 1
    You've combined a lot of half-truths into a largely inaccurate view of the situation. Some things to think about... JavaScript is independent of browsers, the DOM, etc. That's just a commonly used context. Comparing the performance of Nginx to Node.js is like comparing the performance of a car to a blueprint. Also, Node.js isn't single threaded. Calls out to native libraries run threads all the time. There are also various execution models that can be used in JavaScript, providing threading of various kinds. – Brad Feb 03 '19 at 05:31
  • I know node uses libuv to spawn threads for IO related activities. I guess I'm just wondering why javascript at the core is single threaded – John Lippson Feb 03 '19 at 05:32
  • Closely related: https://stackoverflow.com/questions/39879/why-doesnt-javascript-support-multithreading – Thilo Feb 03 '19 at 05:45
  • This thread talks about why staying away from multi-threading may make sense as a conscious decision: https://softwareengineering.stackexchange.com/questions/315454/what-are-the-drawbacks-of-making-a-multi-threaded-javascript-runtime-implementat – Thilo Feb 03 '19 at 05:47

0 Answers0