Raw operating-system-thread wrapper with explicit creation, handle-state checks, and completion waiting. The wrapper owns one operating-system thread handle and returns one Nat32 exit code from wait.


Thread

Methods

create

(code context stackSize --) Starts one thread from one entry-code pointer, one context value, and one explicit stack size in bytes.

Preconditions

  • The wrapper is not already running.

Postconditions

  • The wrapper becomes handle-owning.

isRunning

(-- running) Reports whether the wrapper still owns a thread handle that has not yet been closed by wait or destruction.

wait

(-- exitCode) Waits for thread completion, closes the thread handle, and returns the thread exit code as Nat32.

Preconditions

  • The wrapper is running.

Postconditions

  • The wrapper is no longer running.

Helper constructor

toThread3

(code context stackSize -- threadRef) Constructs one Thread, starts it immediately through create, and returns Ref to the handle-owning wrapper.

Lifecycle and exit codes


Examples

Windows thread example

"String"              use
"control.Int32"       use
"control.Nat32"       use
"control.Natx"        use
"control.drop"        use
"conventions.stdcall" use
"windows/Thread"      use

worker: {parameter: Natx;} Nat32 {convention: stdcall;} codeRef; [
  drop
  7n32
] !worker

{} Int32 {} [
  thread: @worker 0nx 0n32 toThread3;
  result: @thread.wait;
  ("result=" result LF) printList
  0
] "main" exportFunction

Expected Output

result=7

See also