Difference between revisions of "WebAssembly/Threads"
From Lazarus wiki
Jump to navigationJump to search (→Atomic instructions: - document the RTL changes made for the support of atomic instructions with -dFPC_WASM_THREADS) |
m (→Atomic instructions: - Use consistent capitalization for "Interlocked") |
||
Line 16: | Line 16: | ||
[https://www.freepascal.org/docs-html/current/rtl/system/interlockeddecrement.html InterlockedDecrement] | [https://www.freepascal.org/docs-html/current/rtl/system/interlockeddecrement.html InterlockedDecrement] | ||
− | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedincrement.html | + | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedincrement.html InterlockedIncrement] |
− | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedexchange.html | + | [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/interlockedcompareexchange.html InterlockedCompareExchange] | ||
− | [https://www.freepascal.org/docs-html/current/rtl/system/interlockedexchangeadd.html | + | [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). | Note that these require proper alignment (4 bytes) of the target, otherwise they trap (i.e. terminate the program with a stack trace). |
Revision as of 07:37, 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: