Thread defines a simple thread abstraction.
Examples:
Can be a base class (you need to override void run(void) method) :
class MyThread : Thread
{
void function()
{
this.launch();
}
//Thread entry point
protected void run()
{
}
}
or
void main()
{
Thread t = new Thread(&threadStart);
t.launch();
t.wait(); //Wait the end of t thread
}
//Thread entry point
void threadStart (void* userData)
{
}
or
void main()
{
MyObject foo = new MyObject();
Thread t = new Thread(&foo.bar);
t.launch();
t.wait(); //Wait the end of t thread
}
class MyObject
{
void bar(void* user)
{
//...
}
}
- this(void function(void*) func, void* userData = null);
- Construct the thread from a function pointer.
Params:
void function(void*) func |
Entry point of the thread |
void* userData |
Data to pass to the thread function (NULL by default) |
- this(void delegate(void*) dg, void* userData = null);
- Construct the thread from a delegate.
Params:
void delegate(void*) dg |
Entry point of the thread |
void* userData |
Data to pass to the thread function (NULL by default) |
- final void launch();
- Run the thread
- final void wait();
- Wait until the thread finishes
- this();
- Protected constructor
- protected void run();
- Override this method in class derived from Thread.