std
std.atomic
std.exception
std.intrinsic
std.thread
|
|
std.thread
- class ThreadError: object.Exception;
- All exceptions thrown from this module derive from this class.
- class Thread;
- This class encapsulates all threading functionality for the D
programming language. As thread manipulation is a required facility
for garbage collection, all user threads should derive from this
class, and instances of this class should never be explicitly deleted.
- this();
- Initializes a thread object which has no associated executable
function.
- this(void(* fn)());
- Initialized a thread object which is associated with a static
D function.
Params:
void(* fn)() |
The thread function. |
- this(void delegate() dg);
- Initializes a thread object which is associated with a dynamic
D function.
Params:
void delegate() dg |
The thread function. |
- final char[] name();
- Gets the user-readable label for this thread.
Returns:
The name of this thread.
- final void name(char[] n);
- Sets the user-readable label for this thread.
Params:
char[] n |
The new name for this thread. |
- final void start();
- Starts the thread and calls the routine supplied during construction.
If the default ctor was used, this is a no-op.
In:
This routine may only be called once per thread instance.
Throws:
ThreadError if the thread fails to start.
- final bit isRunning();
- Tests whether this thread is running. This function should be
callable from anywhere within the application without a risk of
deadlock.
Returns:
true if the thread is running, false if not.
- final void join();
- Waits for this thread to complete.
Throws:
ThreadError if the operation fails.
- final void suspend();
- Suspends thread execution and loads stack and register data for use
by the suspending thread. Registers should be stored in the order
they would typically appear when pushed onto the execution stack.
This function is reentrant, but resume must be called once for each
call to suspend.
Throws:
ThreadError if the thread is not currently running or if the thread
can not be suspended.
- final void resume();
- Resumes thread execution and frees stack and register data. This
function is reentrant and must be called once for every call to
suspend before the thread is resumed.
Throws:
ThreadError if the thread is not currently running or if the thread
can not be resumed.
- final void* stackTop();
- Should be preceded by a call to suspend.
Returns:
A pointer to the logical top of the execution stack for this thread.
Note that on some operating systems the address may be less than
the address returned by stackBottom.
- final void* stackBottom();
- Should be preceded by a call to suspend.
Returns:
A pointer to the logical bottom of the execution stack for this
thread. Note that on some operating systems the address may be
greater than the address returned by stackTop.
- final void* regFirst();
- Should be preceded by a call to suspend.
Returns:
A pointer to the beginning of an inclusive range of registers
stored by suspend. For example, if a system has registers X, Y, Z,
and they are typically pushed onto the stack in that order, then
this function will point to the value of X on systems where
the stack grows up, or Z on systems where the stack grows down.
- final void* regLast();
- Should be preceded by a call to suspend.
Returns:
A pointer to the end of an inclusive range of registers stored by
suspend. For example, if a system has registers X, Y, Z, and they
are typically pushed onto the stack in that order, then this
function will point to the value of Z on systems where the stack
grows up, or X on systems where the stack grows down.
- static void sleep(uint milliseconds);
- Suspends the calling thread for at least the supplied time.
Params:
uint milliseconds |
The minimum duration the calling thread should be
suspended. |
- static void yield();
- Forces a context switch to occur away from the calling thread.
- static uint count();
- The current thread count.
Returns:
The number of threads currently being tracked by the system.
- static void suspendAll();
- Calls suspend on all running threads.
- static void resumeAll();
- Calls resume on all running threads.
- static Thread getThis();
- The calling thread.
Returns:
The thread object representing the calling thread. The result of
deleting this object is undefined.
- static Thread[] getAll();
- This function is not intended to be used by the garbage collector,
so memory allocation is allowed.
Returns:
An array containing references to all threads currently being
tracked by the system. The result of
deleting any contained objects is undefined.
- static int opApply(int delegate(inout Thread) dg);
- Operates on all threads currently tracked by the system.
- uintC threadCount();
- Identical to Thread.count().
Returns:
The number of threads currently being tracked by the system.
- voidC suspendAllThreads();
- Identical to Thread.suspendAll().
- voidC resumeAllThreads();
- Identical to Thread.resumeAll().
- voidC scanAllThreads(void delegate(void*, void*) fn);
- The main entry point for garbage collection. The supplied delegate
will be passed ranges representing both stack and register values.
Params:
void delegate(void*, void*) fn |
The scanner function. It should scan from p1 through p2 - 1. |
|