Thread
Abstracts native system thread execution
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
Name | Type | Description |
---|---|---|
param | Base | parameter to be passed into the newly executing thread |
GetExecuteID
Returns a unique execution ID
method : public : GetExecuteID() ~ Int
Return
Type | Description |
---|---|
Int | execution ID |
GetName
Returns the thread's name
method : public : GetName() ~ String
Return
Type | Description |
---|---|
String | thread's name |
Run
Prototype for the thread to be executed
method : public : virutal : Run(param:System.Base) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
param | Base | parameter to be passed into the thread |
Sleep
Sleeps the executing thread
function : Sleep(t:Int) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
t | Int | sleep time in milliseconds |