v2026.11.3
All Bundles
Bundle

System support for threads and runtime concurrency

Thread

Abstracts native system thread execution

Example

class Test {
  function : Main(args : String[]) ~ Nil {
    x := Counter->New("x,128");
    y := Counter->New("y,32");
    
    x->Execute(Nil);
    y->Execute(Nil);    

    x->Join();
    y->Join();
  }
}

class Counter from System.Concurrency.Thread {
  @name : String;
  @max : Int;

  New(tag : String) {
    Parent();
    parts := tag->Split(',');
    @name := parts[0]->Trim();
    @max := parts[1]->Trim()->ToInt();
  }

  method : public : Run(param:System.Base) ~ Nil {
    count := 0;
    while(count++ < @max) {
      "{$@name}: {$count}"->PrintLine();
    };
  }
}

Operations

Execute #

Called to execute a new thread

method : public : Execute(param:System.Base) ~ Nil

Parameters

NameTypeDescription
paramBaseparameter to be passed into the newly executing thread

GetCurrentId # function

Gets a number naming the calling thread, whichever thread it is (the program's first thread has one too). Numbers count up from 1 and are never given to another thread, even after this one ends, so they can key state kept per thread.

function : GetCurrentId() ~ Int

Return

TypeDescription
Intthe calling thread's number

Example

id := System.Concurrency.Thread->GetCurrentId();
"running on thread {$id}"->PrintLine();

GetExecuteID #

Returns a unique execution ID

method : public : GetExecuteID() ~ Int

Return

TypeDescription
Intexecution ID

GetName #

Returns the thread's name

method : public : GetName() ~ String

Return

TypeDescription
Stringthread's name

IsAlive # function

Whether the thread GetCurrentId gave a number to is still running, so state kept for a thread can be dropped once it ends

function : IsAlive(id:Int) ~ Bool

Parameters

NameTypeDescription
idInta number from GetCurrentId

Return

TypeDescription
Booltrue while that thread runs; false once it has ended, and for a number never given

Join #

Joins the executing thread with the caller

method : public : Join() ~ Nil

New # constructor

Name of the thread

New(name:String)

Parameters

NameTypeDescription
nameStringname of the thread

Run # virtual

Prototype for the thread to be executed

method : public : virtual : Run(param:System.Base) ~ Nil

Parameters

NameTypeDescription
paramBaseparameter to be passed into the thread

Sleep # function

Sleeps the executing thread

function : Sleep(t:Int) ~ Nil

Parameters

NameTypeDescription
tIntsleep time in milliseconds