Skip to content

Thread

Defined in: src/thread.ts:116

The kernel’s half of a process running on its own thread.

Everything a sync syscall returns goes through the shared page, since a thread waiting on it can’t be handed a message. The page is the control block followed by the return region.

new Thread(proc, regionSize?): Thread

Defined in: src/thread.ts:152

Process

number = defaultRegionSize

Thread

protected readonly _exited: PromiseWithResolvers<number>

Defined in: src/thread.ts:129


protected _interrupts: number = 0

Defined in: src/thread.ts:139


protected optional blockedOn?: number

Defined in: src/thread.ts:127

The syscall the thread is blocked on, so a result that arrives after it gave up can be dropped


protected readonly control: SyscallData

Defined in: src/thread.ts:119


readonly exited: Promise<number>

Defined in: src/thread.ts:132

Resolves with the exit code once the thread is gone


protected optional host?: HostThread

Defined in: src/thread.ts:124


readonly page: SharedArrayBuffer

Defined in: src/thread.ts:117


readonly proc: Process

Defined in: src/thread.ts:153


readonly region: Uint8Array

Defined in: src/thread.ts:122

Where a syscall leaves anything too big for the control block

get interrupts(): number

Defined in: src/thread.ts:148

How many signals have been raised on the thread.

The thread clears pending_signals as soon as it wakes, and it does that on its own core, so the kernel can lose the race to see the flag. This only ever goes up, so a wait that started before a signal can always tell one arrived.

number


get pending_signals(): number

Defined in: src/thread.ts:135

The signals raised but not yet taken, as 1 << sig

number

filled(length): number

Defined in: src/thread.ts:205

Say how much of the region a syscall wrote into it in place

number

number

the same


kill(): void

Defined in: src/thread.ts:256

Stop the thread where it stands. This is the only thing that reaches one that isn’t listening.

void


put(data): number

Defined in: src/thread.ts:198

Put something in the return region. A syscall that has more than fits comes back short, which is what a read does anyway.

Uint8Array

number

how much of it made it


raise(signal): void

Defined in: src/thread.ts:241

Raise a signal on the thread.

A thread blocked in a syscall is woken with EINTR so its handlers run, the same way Linux delivers a signal on the way back to userspace. One that is off computing sees it whenever it makes its next syscall, which is why kill exists.

Signal

void


start(exe, interpreter, source): Promise<void>

Defined in: src/thread.ts:172

Start the thread.

The kernel loads the interpreter and nothing else: the thread runs that, and the interpreter goes and gets the program itself. When a program needs no interpreter it is its own.

string

string

Uint8Array

the interpreter’s bytes, read out of the file system

Promise<void>


protected syscall(__namedParameters): Promise<void>

Defined in: src/thread.ts:210

SyscallMessage

Promise<void>


protected wake(value): void

Defined in: src/thread.ts:228

number

void