4 ms·
On the browser you have Web Workers and Service Workers, both run on separate threads :). https://web.dev/workers-overview/#:~:text=Web%20workers%20and%20servi
by koonsolo 4y ago
On the browser you have Web Workers and Service Workers, both run on separate threads :).
https://web.dev/workers-overview/#:~:text=Web%20workers%20and%20service%20workers%20%23&text=Both%20run%20in%20a%20secondary,limited%20access%20to%20browser%20APIs https://web.dev/workers-overview/#:~:text=Web%20workers%20an....
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...
https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API https://developer.mozilla.org/en-US/docs/Web/API/Service_Wor...
- kllrnohj 4y agoThose are really more like separate processes. There's no ability to do a shared heap in browser JS, meaning it functionally doesn't have threads. Whether or not workers are actually implemented as threads or processes in the runtime is irrelevant. As far as the JS code itself is concerned & what you can do with it, browser JS is lacking multi-threading. There's just no way to do a shared heap, and that is the biggest defining difference between a process and a thread.
- afavour 4y agoThe web has SharedArrayBuffer. It’s just difficult to work with.
- kllrnohj 4y agoCreating a shared memory allocation between 2 processes doesn't convert them to threads. The heaps are still distinct.
- azakai 4y agoThe JavaScript heaps are distinct, that's true, but there is a single shared wasm heap which is used from multiple threads. That is enough to implement the pthreads API. Applications like Photoshop and Google Earth use ptheads on the Web so their compiled C++ is multithreaded, very similar to how it would run natively, and with similar responsiveness and throughput speedups. Though there are some limitations too, see https://emscripten.org/docs/porting/pthreads.html https://emscripten.org/docs/porting/pthreads.html
- flohofwoe 4y agoThe entire WASM heap is a single ArrayBuffer (or SharedArrayBuffer) object.
- koonsolo 4y agoPractically speaking, you just want shared memory in your threads. What would a shared heap offer that shared memory can't?