D
Language
Phobos
Comparisons
object
std
std.base64
std.bitarray
std.boxer
std.compiler
std.conv
std.ctype
std.date
std.demangle
std.file
std.format
std.gc
std.intrinsic
std.math
std.md5
std.mmfile
std.openrj
std.outbuffer
std.path
std.process
std.random
std.recls
std.regexp
std.socket
std.socketstream
std.stdint
std.stdio
std.cstream
std.stream
std.string
std.system
std.thread
std.uni
std.uri
std.utf
std.zip
std.zlib
std.windows
std.linux
std.c
std.c.stdio
std.c.windows
std.c.linux
|
std.thread
The thread module defines the class Thread.
Thread is the basis
for writing multithreaded applications. Each thread
has a unique instance of class Thread associated with it.
It is important to use the Thread class to create and manage
threads as the garbage collector needs to know about all the threads.
- typedef ... thread_hdl
- The type of the thread handle used by the operating system.
- class Thread
- One for each thread.
- class ThreadError
- Thrown for errors.
The members of Thread are:
- this()
- Constructor used by classes derived from Thread that
override main().
- this(int (*fp)(void*), void* arg)
- Constructor used by classes derived from Thread that
override run().
- this(int delegate() dg)
- Constructor used by classes derived from Thread that
override run().
- thread_hdl hdl;
- The handle to this thread assigned by the operating system.
This is set to thread_id.init if the thread hasn't been started
yet.
- void start();
- Create a new thread and start it running. The new thread
initializes itself and then calls run().
start() can only be called once.
- int run(void* p);
- Entry point for a thread. If not overridden, it calls the
function pointer fp and argument arg passed in
the constructor, or the delegate dg. The return value
is the thread exit code, which is normally 0.
- void wait();
- Wait for this thread to terminate.
Throws ThreadError
if the thread hasn't begun yet or
is called on itself.
Simply returns if thread has already terminated.
- void wait(unsigned milliseconds);
- Wait for this thread to terminate or until milliseconds time has
elapsed, whichever occurs first.
Throws ThreadError
if the thread hasn't begun yet or
is called on itself.
Simply returns if thread has already terminated.
- TS getState();
- Returns the state of the thread.
The state is one of the following:
TS
| Description
|
INITIAL
| The thread hasn't been started yet.
|
RUNNING
| The thread is running or paused.
|
TERMINATED
| The thread has ended.
|
- void setPriority(PRIORITY* p);
- Adjust the priority of this thread.
PRIORITY
| Description
|
INCREASE
| Increase thread priority
|
DECREASE
| Decrease thread priority
|
IDLE
| Assign thread low priority
|
CRITICAL
| Assign thread high priority
|
- static Thread getThis();
- Returns a reference to the Thread for the thread
that called the function.
- static Thread[] getAll();
- Returns an array of all the threads currently running.
- void pause();
- Suspend execution of this thread.
- void resume();
- Resume execution of this thread.
- static void pauseAll();
- Suspend execution of all threads but this thread.
- static void resumeAll();
- Resume execution of all paused threads.
- static void yield();
- Give up the remainder of this thread's time slice.
|