0

I want to implement a counter code that have 2 main parts: 1. A Counter worker that continuously increment the WebAssembly.Memory as a counter variable, 2. The main code that reads the counter value from counter thread whenever it wants. I want to implement this code using a web worker and postMessage for passing the value of counter. The WebAssembly.Memory is the container of the counter and is defined in the main code and is being increasing in the counter worker. In fact I want to use WebAssembly.Memory like SharedArrayBuffer. My question is: how to implement the worker part of code and to increment the counter in JS and then read it in the main code? In fact I don't want to use multithreading in WASM, but I just want to implement my goal in Javascript, because I believe today multithreading is just a beta version and is in fact multi-tasking not multithreading. And it is not possible to run 2 threads completely simultaneously.

  • If you want just a counter just send `postMessage({counterInteger})`, not the whole SharedArray buffer. You won't get any advantage of SharedArray. – Bumsik Kim Jan 21 '20 at 10:22
  • And I believe there is a slight misunderstanding about JS and Wasm. Wasm is not special at all when it comes to its capabilities compared to JS. What JS can't do is what Wasm can't. Wasm multithreading is the same as JS Web Worker + SharedArrayBuffer (for now). – Bumsik Kim Jan 21 '20 at 10:32
  • Does this answer your question? [Can you share WebAssembly memory between Web Workers?](https://stackoverflow.com/questions/59818702/can-you-share-webassembly-memory-between-web-workers) – ColinE Jan 21 '20 at 15:09
  • up to certain level, but I dont want use multithreading in wasm and also sharedarraybuffer. I want to use WebAssembly by JS code in the worker. –  Jan 21 '20 at 15:19

0 Answers0