StructPthread

data class StructPthread(val self: WasmPtr<StructPthread>, val prev: WasmPtr<StructPthread>, val next: WasmPtr<StructPthread>, val sysinfo: uintptr_t, val canary: uintptr_t, val tlsBase: WasmPtr<Unit>, val mailbox: WasmPtr<Unit>, val mailboxRefcount: Int, val waitingAsync: Int, val sleeping: Byte)(source)

Internal Pthread struct

pthread_impl.h

Constructors

Link copied to clipboard
constructor(self: WasmPtr<StructPthread>, prev: WasmPtr<StructPthread>, next: WasmPtr<StructPthread>, sysinfo: uintptr_t, canary: uintptr_t, tlsBase: WasmPtr<Unit>, mailbox: WasmPtr<Unit>, mailboxRefcount: Int, waitingAsync: Int, sleeping: Byte)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

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.

Link copied to clipboard

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;

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

When dynamic linking is enabled, threads use this to facilitate the synchronization of loaded code between threads. See emscripten_futex_wait.c

Link copied to clipboard
Link copied to clipboard

The TLS base to use the main module TLS data. Secondary modules still require dynamic allocation.

Link copied to clipboard

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.