Threads

In the previous section, we used Web Workers to move Wasm modules into worker threads, which allowed us to call Wasm functions without blocking the main thread. However, passing messages between worker threads has performance limitations. In an effort to address this issue, a threads feature was proposed for WebAssembly.

The proposal, currently in Phase 1, is described in detail at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md. Per the proposal documentation, the threads feature adds a new shared linear memory type and some new operations for atomic memory access. This proposal is relatively limited in scope. Eberhardt provides the following elaboration in his blog post:

"Notably, this proposal does not introduce a mechanism for creating threads (which has caused a lot of debate) instead this functionality is supplied by the host. Within the context of wasm executed by the browser this will be the familiar WebWorkers."

Although the feature wouldn't allow for the creation of threads, it provides a simpler way of sharing data between the worker threads we create in JavaScript.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset