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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Thread(
proc,regionSize?):Thread
Defined in: src/thread.ts:152
Parameters
Section titled “Parameters”regionSize?
Section titled “regionSize?”number = defaultRegionSize
Returns
Section titled “Returns”Thread
Properties
Section titled “Properties”_exited
Section titled “_exited”
protectedreadonly_exited:PromiseWithResolvers<number>
Defined in: src/thread.ts:129
_interrupts
Section titled “_interrupts”
protected_interrupts:number=0
Defined in: src/thread.ts:139
blockedOn?
Section titled “blockedOn?”
protectedoptionalblockedOn?: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
control
Section titled “control”
protectedreadonlycontrol:SyscallData
Defined in: src/thread.ts:119
exited
Section titled “exited”
readonlyexited:Promise<number>
Defined in: src/thread.ts:132
Resolves with the exit code once the thread is gone
protectedoptionalhost?:HostThread
Defined in: src/thread.ts:124
readonlypage:SharedArrayBuffer
Defined in: src/thread.ts:117
readonlyproc:Process
Defined in: src/thread.ts:153
region
Section titled “region”
readonlyregion:Uint8Array
Defined in: src/thread.ts:122
Where a syscall leaves anything too big for the control block
Accessors
Section titled “Accessors”interrupts
Section titled “interrupts”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”number
pending_signals
Section titled “pending_signals”Get Signature
Section titled “Get Signature”get pending_signals():
number
Defined in: src/thread.ts:135
The signals raised but not yet taken, as 1 << sig
Returns
Section titled “Returns”number
Methods
Section titled “Methods”filled()
Section titled “filled()”filled(
length):number
Defined in: src/thread.ts:205
Say how much of the region a syscall wrote into it in place
Parameters
Section titled “Parameters”length
Section titled “length”number
Returns
Section titled “Returns”number
the same
kill()
Section titled “kill()”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.
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”number
how much of it made it
raise()
Section titled “raise()”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.
Parameters
Section titled “Parameters”signal
Section titled “signal”Returns
Section titled “Returns”void
start()
Section titled “start()”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.
Parameters
Section titled “Parameters”string
interpreter
Section titled “interpreter”string
source
Section titled “source”Uint8Array
the interpreter’s bytes, read out of the file system
Returns
Section titled “Returns”Promise<void>
syscall()
Section titled “syscall()”
protectedsyscall(__namedParameters):Promise<void>
Defined in: src/thread.ts:210
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”SyscallMessage
Returns
Section titled “Returns”Promise<void>
wake()
Section titled “wake()”
protectedwake(value):void
Defined in: src/thread.ts:228
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void