pub fn run(module: &mut Module) -> Result<Option<ThreadCount>, Error>
Expand description
Execute the transformation on the parsed Wasm module specified.
This function will prepare Module
to be run on multiple threads,
performing steps such as:
- All data segments are switched to “passive” data segments to ensure they’re only initialized once (coming later)
- If memory is exported from this module, it is instead switched to being imported (with the same parameters).
- The imported memory is required to be
shared
, ensuring it’s backed by aSharedArrayBuffer
on the web. - A
global
for a thread ID is injected. - Four bytes in linear memory are reserved for the counter of thread IDs.
- A
start
function is injected (or prepended if one already exists) which initializes memory for the first thread and otherwise allocates thread ids for all threads. - Some stack space is prepared for each thread after the first one.
More and/or less may happen here over time, stay tuned!