WebAssembly/Threads

From Free Pascal wiki
Revision as of 07:37, 24 May 2022 by Nickysn (talk | contribs) (→‎Atomic instructions: - Use consistent capitalization for "Interlocked")
Jump to navigationJump to search

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

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:

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: