JFLib

plat/web_threads.rs#

Source: lib/plat/web_threads.rs

OS primitives for the existing pool.rs scheduler. Each Worker instantiates the
same module and shared memory, with its own __stack_pointer. Only the app worker
enters the UI. LLD's atomic memory initializer runs once across all instances.
  • struct Thread A browser worker with an exclusively owned stack and a join completion word.

impl Thread

  • fn join(self) Wait until JavaScript has returned from WASM before releasing its stack.

  • fn spawn(stack: usize, f: Box<dyn FnOnce() + Send>) -> Option<Thread> Start a closure on a compute worker; return None if the host cannot start it.

  • struct Sem(AtomicU32) Counting semaphore backed by WebAssembly atomics and worker-only Atomics.wait.

impl Sem

  • fn new(initial: u32) -> Option<Self> Construct a semaphore with the specified number of available units.
  • fn post(&self, count: u32) Publish work and wake up to count sleeping workers.
  • fn wait(&self, timeout: i32) -> bool Take a unit; negative timeout waits indefinitely, zero only tries once.

Source: docs/API.md in the JFLib repository.