wasm_sync
wasm_sync offers synchronization primitives that work in both browser and native contexts.
In web browsers, use of atomic wait instructions on the main thread causes an error. This prevents the use of standard library synchronization primitives within web contexts. wasm_sync solves this problem by busy-spinning on the main thread. Other threads, like dedicated web workers, still use atomic wait instructions.
On native platforms, wasm_sync simply re-exports the standard library's synchronization primitives.
Supported primitives
wasm_sync::Condvarwasm_sync::Mutexwasm_sync::RwLockwasm_sync::Oncewasm_sync::OnceLock
Usage
Instead of importing a standard library primitive, import the wasm_sync variant. For example:
use Arc;
use thread;
use Mutex;
let mutex = new;
let c_mutex = clone;
spawn.join.expect;
assert_eq!;