News for hackers. Stuff that matters.
Re:CPython's main branch running in the browser with WebAsse... by benno128 on Monday November 29, 2021 @06:10AM (#29378454)
In WebAssembly.sh (https://github.com/wasmerio/webassembly.sh) they run WASM binaries in a Web Worker and then use `SharedArrayBuffer` to block the WebWorker while the main thread does some work (e.g. collect input). You could use a similar solution.

When building Runno (https://runno.dev) I forked off that project and did a bunch of other things on top to get blocking to work in Safari and non-cross-origin-isolated contexts.

Ultimately I think it's JavaScript's (or whichever host language) responsibility to block when the binary calls out (if that is the expected semantics).

Re:CPython's main branch running in the browser with WebAsse... by est31 on Monday November 29, 2021 @10:16AM (#29380780)
Does the SharedArrayBuffer approach offer any way to tell the OS scheduler to wait? Because the only waiting method I know of is busy waiting, aka wasting cycles at 100% of a CPU core. In normal processes you can call a sleep function, which saves CPU cycles, but there is no synchronous method for that available in javascript.
Re:CPython's main branch running in the browser with WebAsse... by benno128 on Monday November 29, 2021 @02:39PM (#29384224)
It's part of the Atomics feature set (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...). You have a shared chunk of memory and you say "please sleep until this memory changes". Then it's up to the host to change that memory.
Re:CPython's main branch running in the browser with WebAsse... by est31 on Tuesday November 30, 2021 @02:35AM (#29389839)
Oh that's pretty neat, didn't know about that.