-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Add proper support for all major platforms:
- Standard
stdtargets, as we already do. - Embedded
no_stdtargets. - The web, ideally via web workers.
To support these platforms, we've got to figure out what we are going to do with these fundamental threading types:
- The
Mutexused for theThreadPoolstate. - The
Arc<AtomicBool>andWeak<AtomicBool>used for heartbeats. - The
SignalandBlockerprimitives, both of which are build directly on Mara's amazing futex crateatomic_wait.
On std, these are all fine. For web, the web assembly atomics proposal supports exactly the futex wait and notify calls we need, with the caveat that creating web workers is not as simple as std::thread::spawn and we can never block the main js thread. We'll have to leave spawning and managing workers to users, and the build-system will suck, but that's acceptable.
For embedded, things are more complicated. None of these primitives will work, so we will either have to fall back to synchronous execution or add an async executor and go concurrent. Many no_std targets now have an async executor (like embassy for example), and it would be good if we could run on-top of them. On these platforms, users will need to set up a worker task, we won't use heartbeats, and block_on, join and scope will all have to be synchronous.
This boils down to the following features:
- the default: A
core-onlyno_stdfallback with only sequential operation, with no parallelism or concurrency. extern: Stillno_std, but supports concurrency with externally added async workers.web-futures: A concurrent fallback based onwasm_bindgen_futures::spawn_local.web-worker: A full parallel thread-pool backed by web workers and wasm atomics.std: A full parallel thread-pool backed by thestdoperating system primitives.