3 ms·
>Other languages that have a GIL (and the same restriction) are Javascript (including Node.js) Not quite true; JS just doesn't support threads at all. It's asy
by eurleif 11y ago
>Other languages that have a GIL (and the same restriction) are Javascript (including Node.js)
Not quite true; JS just doesn't support threads at all. It's asynchronous and single-threaded. In node.js's case, an event loop uses a system call like epoll or kqueue to wait for many events at a time, and dispatches those events to the correct callbacks.
You can do parallelism in JS with Web Workers, and they do use native OS threads, but they lack shared memory, and can only communicate using message passing. So from the perspective of the JS code, they behave more like processes than threads. No GIL, in any case.
- Matthias247 11y agoI think thats not directly language related but an implementation detail - although a very important one. Javascript on the JVM (Nashorn) allows full multithreading - including then the need for all the common synchronization stuff. But of course - Javascript and also the typical Javascript libraries were not made with multithreading in mind.