Difference between revisions of "WebAssembly/Threads"
From Free Pascal wiki
Jump to navigationJump to search (→Atomic instructions: - document the RTL changes made for the support of atomic instructions with -dFPC_WASM_THREADS) |
|||
Line 12: | Line 12: | ||
[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 -dFPC_WASM_THREADS, 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/interlockedincrement.html InterLockedIncrement] | ||
+ | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedexchange.html InterLockedExchange] | ||
+ | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedcompareexchange.html InterlockedCompareExchange] | ||
+ | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedexchangeadd.html 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 == | == Thread support == |
Revision as of 07:31, 24 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 -dFPC_WASM_THREADS, 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: