StructPthread
Internal Pthread struct
Constructors
Properties
The lowest level of the proxying system. Other threads can enqueue messages on the mailbox and notify this thread to asynchronously process them once it returns to its event loop. When this thread is shut down, the mailbox is closed (see below) to prevent further messages from being enqueued and all the remaining queued messages are dequeued and their shutdown handlers are executed. This allows other threads waiting for their messages to be processed to be notified that their messages will not be processed after all.
To ensure that no other thread is concurrently enqueueing a message when this thread shuts down, maintain an atomic refcount. Enqueueing threads atomically increment the count from a nonzero number to acquire the mailbox and decrement the count when they finish. When this thread shuts down it will atomically decrement the count and wait until it reaches 0, at which point the mailbox is considered closed and no further messages will be enqueued. _Atomic int mailbox_refcount;
When dynamic linking is enabled, threads use this to facilitate the synchronization of loaded code between threads. See emscripten_futex_wait.c
Whether the thread has executed an Atomics.waitAsync
on this pthread struct and can be notified of new mailbox messages via Atomics.notify
. Otherwise, such as when the environment does not implement Atomics.waitAsync
or when the thread has not had a chance to initialize itself yet, the notification has to fall back to the postMessage path. Once this becomes true, it remains true so we never fall back to postMessage unnecessarily.