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. A new thread may be created using either derivation or composition, as in the following example.

Constructors

this
this(void function() fn, size_t sz)

Initializes a thread object which is associated with a static D function.

this
this(void delegate() dg, size_t sz)

Initializes a thread object which is associated with a dynamic D function.

this
this(size_t sz)
Undocumented in source.

Destructor

~this
~this()

Cleans up any remaining resources used by this object.

Members

Aliases

TLSKey
alias TLSKey = uint
Undocumented in source.
TLSKey
alias TLSKey = pthread_key_t
Undocumented in source.

Functions

join
Throwable join(bool rethrow)

Waits for this thread to complete. If the thread terminated as the result of an unhandled exception, this exception will be rethrown.

start
Thread start()

Starts the thread and invokes the function or delegate passed upon construction.

Properties

PRIORITY_DEFAULT
int PRIORITY_DEFAULT [@property getter]

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

PRIORITY_DEFAULT
int PRIORITY_DEFAULT [@property getter]

The default scheduling priority that is set for a thread. On systems where multiple scheduling policies are defined, this value represents the default priority for the scheduling policy of the process.

PRIORITY_MAX
const(int) PRIORITY_MAX [@property getter]

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

PRIORITY_MAX
const(int) PRIORITY_MAX [@property getter]

The maximum scheduling priority that may be set for a thread. On systems where multiple scheduling policies are defined, this value represents the maximum valid priority for the scheduling policy of the process.

PRIORITY_MIN
int PRIORITY_MIN [@property getter]

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

PRIORITY_MIN
int PRIORITY_MIN [@property getter]

The minimum scheduling priority that may be set for a thread. On systems where multiple scheduling policies are defined, this value represents the minimum valid priority for the scheduling policy of the process.

isRunning
bool isRunning [@property getter]

Tests whether this thread is running.

priority
int priority [@property getter]

Gets the scheduling priority for the associated thread.

priority
int priority [@property setter]

Sets the scheduling priority for the associated thread.

Static functions

getThis
Thread getThis()

Provides a reference to the calling thread.

sleep
void sleep(Duration val)

Suspends the calling thread for at least the supplied period. This may result in multiple OS calls if period is greater than the maximum sleep duration supported by the operating system.

yield
void yield()

Forces a context switch to occur away from the calling thread.

Variables

fakePriority
int fakePriority;
Undocumented in source.
m_reg
uint[8] m_reg;
Undocumented in source.
m_reg
ulong[16] m_reg;
Undocumented in source.
m_reg
uint[8] m_reg;
Undocumented in source.
m_reg
ulong[16] m_reg;
Undocumented in source.
m_reg
ulong[33] m_reg;
Undocumented in source.
m_reg
uint[16] m_reg;
Undocumented in source.
m_reg
uint[32] m_reg;
Undocumented in source.
m_reg
ulong[32] m_reg;
Undocumented in source.

Inherited Members

From ThreadBase

destructBeforeDtor
bool destructBeforeDtor()

Cleans up any remaining resources used by this object.

tlsGCdataInit
void tlsGCdataInit()
Undocumented in source. Be warned that the author may not have intended to support it.
initDataStorage
void initDataStorage()
Undocumented in source. Be warned that the author may not have intended to support it.
destroyDataStorage
void destroyDataStorage()
Undocumented in source. Be warned that the author may not have intended to support it.
destroyDataStorageIfAvail
void destroyDataStorageIfAvail()
Undocumented in source. Be warned that the author may not have intended to support it.
join
Throwable join(bool rethrow)

Waits for this thread to complete. If the thread terminated as the result of an unhandled exception, this exception will be rethrown.

id
ThreadID id [@property getter]

Gets the OS identifier for this thread.

name
string name [@property getter]

Gets the user-readable label for this thread.

name
string name [@property setter]

Sets the user-readable label for this thread.

isDaemon
bool isDaemon [@property getter]

Gets the daemon status for this thread. While the runtime will wait for all normal threads to complete before tearing down the process, daemon threads are effectively ignored and thus will not prevent the process from terminating. In effect, daemon threads will be terminated automatically by the OS when the process exits.

isDaemon
bool isDaemon [@property setter]

Sets the daemon status for this thread. While the runtime will wait for all normal threads to complete before tearing down the process, daemon threads are effectively ignored and thus will not prevent the process from terminating. In effect, daemon threads will be terminated automatically by the OS when the process exits.

isMainThread
bool isMainThread [@property getter]

Tests whether this thread is the main thread, i.e. the thread that initialized the runtime

isRunning
bool isRunning [@property getter]

Tests whether this thread is running.

getThis
ThreadBase getThis()

Provides a reference to the calling thread.

getAll
ThreadBase[] getAll()

Provides a list of all threads currently being tracked by the system. Note that threads in the returned array might no longer run (see ThreadBase..isRunning).

opApply
int opApply(int delegate(ref ThreadBase) dg)

Operates on all threads currently being tracked by the system. The result of deleting any Thread object is undefined. Note that threads passed to the callback might no longer run (see ThreadBase..isRunning).

run
void run()
Undocumented in source. Be warned that the author may not have intended to support it.
sm_this
ThreadBase sm_this;
Undocumented in source.
sm_main
ThreadBase sm_main;
Undocumented in source.
m_addr
ThreadID m_addr;
Undocumented in source.
m_call
Callable m_call;
Undocumented in source.
m_name
string m_name;
Undocumented in source.
m_sz
size_t m_sz;
Undocumented in source.
m_isDaemon
bool m_isDaemon;
Undocumented in source.
m_isInCriticalRegion
bool m_isInCriticalRegion;
Undocumented in source.
m_unhandled
Throwable m_unhandled;
Undocumented in source.
setThis
void setThis(ThreadBase t)

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

m_main
StackContext m_main;
Undocumented in source.
m_curr
StackContext* m_curr;
Undocumented in source.
m_lock
bool m_lock;
Undocumented in source.
pushContext
void pushContext(StackContext* c)

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

popContext
void popContext()
Undocumented in source.
slock
Mutex slock [@property getter]

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

criticalRegionLock
Mutex criticalRegionLock [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
initLocks
void initLocks()
Undocumented in source. Be warned that the author may not have intended to support it.
termLocks
void termLocks()
Undocumented in source. Be warned that the author may not have intended to support it.
sm_cbeg
StackContext* sm_cbeg;
Undocumented in source.
sm_tbeg
ThreadBase sm_tbeg;
Undocumented in source.
sm_tlen
size_t sm_tlen;
Undocumented in source.
pAboutToStart
ThreadBase* pAboutToStart;
Undocumented in source.
nAboutToStart
size_t nAboutToStart;
Undocumented in source.
prev
ThreadBase prev;
Undocumented in source.
next
ThreadBase next;
Undocumented in source.
add
void add(StackContext* c)

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

remove
void remove(StackContext* c)
Undocumented in source.
add
void add(ThreadBase t, bool rmAboutToStart)

//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

remove
void remove(ThreadBase t)
Undocumented in source.

Meta