Difference between revisions of "WebAssembly/Threads"
From Free Pascal wiki
Jump to navigationJump to searchm (→Atomic instructions: - Use consistent capitalization for "Interlocked") |
(→Atomic instructions: - there's now a new compiler option to enable WASM threads: -CTwasmthreads, it should be used to compile the RTL, instead of -dFPC_WASM_THREADS) |
||
Line 13: | Line 13: | ||
[https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md The proposed specs] | [https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md The proposed specs] | ||
− | When the Free Pascal RTL is compiled with - | + | When the Free Pascal RTL is compiled with -CTwasmthreads, the following RTL functions will use the new atomic instructions and thus should be thread safe in a multithreaded environment: |
[https://www.freepascal.org/docs-html/current/rtl/system/interlockeddecrement.html InterlockedDecrement] | [https://www.freepascal.org/docs-html/current/rtl/system/interlockeddecrement.html InterlockedDecrement] |
Revision as of 00:32, 28 May 2022
Thread support
This page contains some collected informations on the features needed for thread support in WebAssembly (in the browser).
Thread support consists of 2 parts:
- Atomic instructions.
- Actually starting a thread.
Atomic instructions
When the Free Pascal RTL is compiled with -CTwasmthreads, the following RTL functions will use the new atomic instructions and thus should be thread safe in a multithreaded environment:
InterlockedDecrement InterlockedIncrement InterlockedExchange InterlockedCompareExchange InterlockedExchangeAdd
Note that these require proper alignment (4 bytes) of the target, otherwise they trap (i.e. terminate the program with a stack trace).
Thread support
Webassembly relies on the hosting environment to actually start threads.
Some extra info: