writefln("Current process id: %s", getpid());
class DerivedThread : Thread
{
this()
{
super( &run );
}
private :
void run()
{
printf( "Derived thread running.\n" );
}
}
void threadFunc()
{
printf( "Composed thread running.\n" );
}
// create instances of each type
Thread derived = new DerivedThread();
Thread composed = new Thread( &threadFunc );
// start both threads
derived.start();
composed.start();
| void function() fn | The thread function. |
| uint sz | The stack size for this thread. |
| void delegate() dg | The thread function. |
| uint sz | The stack size for this thread. |
| bool rethrow | Rethrow any unhandled exception which may have caused this thread to terminate. |
| string val | The new name of this thread. |
| bool val | The new daemon status for this thread. |
| int val | The new scheduling priority of this thread. |
| Duration val | The minimum duration the calling thread should be suspended. |
Thread.sleep( dur!("msecs")( 50 ) ); // sleep for 50 milliseconds
Thread.sleep( dur!("seconds")( 5 ) ); // sleep for 5 seconds
| long period | The minimum duration the calling thread should be suspended, in 100 nanosecond intervals. |
Thread.sleep( 500_000 ); // sleep for 50 milliseconds Thread.sleep( 50_000_000 ); // sleep for 5 seconds
| int delegate(ref Thread) dg | The supplied code as a delegate. |
| Thread.ThreadAddr addr | The thread identifier to search for. |
| Thread t | A reference to the current thread. May be null. |
| ScanAllThreadsTypeFn scan | The scanner function. It should scan from p1 through p2 - 1. |
| ScanAllThreadsFn scan | The scanner function. It should scan from p1 through p2 - 1. |
| IsMarkedDg isMarked | The function used to check if is marked. |
| void function() fn | The thread function. |
| void delegate() dg | The thread function. |
| Thread t | The thread to add. |
| Thread t | The thread to remove. |
| bool rethrow | Rethrow any unhandled exception which may have caused the current thread to terminate. |
class DerivedFiber : Fiber
{
this()
{
super( &run );
}
private :
void run()
{
printf( "Derived fiber running.\n" );
}
}
void fiberFunc()
{
printf( "Composed fiber running.\n" );
Fiber.yield();
printf( "Composed fiber running.\n" );
}
// create instances of each type
Fiber derived = new DerivedFiber();
Fiber composed = new Fiber( &fiberFunc );
// call both fibers once
derived.call();
composed.call();
printf( "Execution returned to calling context.\n" );
composed.call();
// since each fiber has run to completion, each should have state TERM
assert( derived.state == Fiber.State.TERM );
assert( composed.state == Fiber.State.TERM );
| void function() fn | The fiber function. |
| uint sz | The stack size for this fiber. |
| void delegate() dg | The fiber function. |
| uint sz | The stack size for this fiber. |
| bool rethrow | Rethrow any unhandled exception which may have caused this fiber to terminate. |
| fn | The fiber function. |
| dg | The fiber function. |
| Throwable t | The object to throw. |