core.thread.threadbase

The threadbase module provides OS-independent code for thread storage and management.

Module Deinitializers 1

shared static ~this()

Types 19

aliasrt_tlsgc_init = externDFunc!("rt.tlsgc.init", void * function() nothrow @nogc)
aliasrt_tlsgc_destroy = externDFunc!("rt.tlsgc.destroy", void function(void *) nothrow @nogc)
aliasScanDg = void delegate(void * pstart, void * pend) nothrow
aliasrt_tlsgc_scan = externDFunc!("rt.tlsgc.scan", void function(void *, scope ScanDg) nothrow)
classThreadException : Exception

Base class for thread exceptions.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)

Base class for thread errors to be used for function inside GC when allocations are unavailable.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
aliasswapContext = externDFunc!("core.thread.osthread.swapContext", void * function(void *) nothrow @nogc)
aliasgetStackBottom = externDFunc!("core.thread.osthread.getStackBottom", void * function() nothrow @nogc)
aliasgetStackTop = externDFunc!("core.thread.osthread.getStackTop", void * function() nothrow @nogc)
Fields
ThreadBase sm_this
ThreadBase sm_main
ThreadID m_addr
Callable m_call
string m_name
size_t m_sz
bool m_isDaemon
Throwable m_unhandled
StackContext * m_curr
bool m_lock
private void * m_tlsgcdata
private void * m_tlsrtdata
void[mutexClassInstanceSize] _slock
StackContext * sm_cbeg
ThreadBase sm_tbeg
size_t sm_tlen
private ThreadBase * pAboutToStart
private size_t nAboutToStart
Methods
bool destructBeforeDtor() nothrow @nogcCleans up any remaining resources used by this object.
void * tlsGCData() ref nothrow @nogc
void tlsRTdataInit() nothrow @nogc
void initDataStorage() nothrow
void destroyDataStorage() nothrow @nogc
void destroyDataStorageIfAvail() nothrow @nogc
Throwable join(bool rethrow = true)Waits for this thread to complete. If the thread terminated as the result of an unhandled exception, this exception will be rethrown.
ThreadID id() @property @safe @nogcGets the OS identifier for this thread.
string name() @property @safe @nogcGets the user-readable label for this thread.
void name(string val) @property @safe @nogcSets the user-readable label for this thread.
bool isDaemon() @property @safe @nogcGets 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 pre...
void isDaemon(bool val) @property @safe @nogcSets 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 pre...
bool isMainThread() @property nothrow @nogcTests whether this thread is the main thread, i.e. the thread that initialized the runtime
bool isRunning() @property nothrow @nogcTests whether this thread is running.
ThreadBase getThis() @safe nothrow @nogcProvides a reference to the calling thread.
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).
int opApply(scope 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.i...
private ThreadBase[] getAllImpl(alias resize)()
private void yield() @nogc nothrowForces a context switch to occur away from the calling thread.
void run()
void setThis(ThreadBase t) nothrow @nogc
void pushContext(StackContext * c) nothrow @nogc
void popContext() nothrow @nogc
private StackContext * topContext() nothrow @nogc
void[] savedRegisters() nothrow @nogcGet an array of the current saved registers for this thread.
Mutex slock() @property nothrow @nogc
void initLocks() @nogc nothrow
void termLocks() @nogc nothrow
void add(StackContext * c) nothrow @nogc
void remove(StackContext * c) nothrow @nogc
void incrementAboutToStart(ThreadBase t) nothrow @nogc
void add(ThreadBase t, bool rmAboutToStart = true) nothrow @nogc
void remove(ThreadBase t) nothrow @nogc
void registerThis(ThreadBase t, bool rmAboutToStart = true) nothrow @nogc
Constructors
this(void function() fn, size_t sz = 0)
this(void delegate() dg, size_t sz = 0)
this(size_t sz = 0)
private aliasattachThread = externDFunc!("core.thread.osthread.attachThread", ThreadBase function(ThreadBase) @nogc nothrow)
private aliasresume = externDFunc!("core.thread.osthread.resume", void function(ThreadBase) nothrow @nogc)

Indicates the kind of scan being performed by thread_scanAllType.

stackThe stack and/or registers are being scanned.
tlsTLS data is being scanned.
aliasScanAllThreadsFn = void delegate(void *, void *) nothrow

The scanning function.

aliasScanAllThreadsTypeFn = void delegate(ScanType, void *, void *) nothrow

ditto

aliascallWithStackShellDg = void delegate(void * sp) nothrow
private aliascallWithStackShell = externDFunc!("core.thread.osthread.callWithStackShell", void function(scope callWithStackShellDg) nothrow)
private aliasthread_yield = externDFunc!("core.thread.osthread.thread_yield", void function() @nogc nothrow)
aliasProcessTLSGCDataDg = void * delegate(void * data) nothrow

Functions 24

fnvoid _d_monitordelete_nogc(Object h) @nogc nothrow;
fnvoid thread_term_tpl(ThreadT, MainThreadStore)(ref MainThreadStore _mainThreadStore) @nogc nothrowTerminates the thread module. No other thread routine may be called afterwards.
fnbool thread_isMainThread() nothrow @nogc
fnThreadT thread_attachThis_tpl(ThreadT)()Registers the calling thread for use with the D Runtime. If this routine is called for a thread which is already registered, no action is performed.
fnvoid thread_detachThis() nothrow @nogcDeregisters the calling thread from use with the runtime. If this routine is called for a thread which is not registered, the result is undefined.
fnvoid thread_detachByAddr(ThreadID addr)Deregisters the given thread from use with the runtime. If this routine is called for a thread which is not registered, the result is undefined.
fnvoid thread_detachInstance(ThreadBase t) nothrow @nogcditto
fnThreadBase thread_findByAddr(ThreadID addr)Search the list of all threads for a thread with the given thread identifier.
fnvoid thread_setThis(ThreadBase t) nothrow @nogcSets the current thread to a specific reference. Only to be used when dealing with externally-created threads (in e.g. C code). The primary use of this function is when ThreadBase.getThis() must re...
fnvoid thread_joinAll()Joins all non-daemon threads that are currently running. This is done by performing successive scans through the thread list until a scan consists of only daemon threads.
fnvoid thread_postRestartTheWorld() nothrowRun the necessary operation required after the world was resumed.
fnvoid thread_resumeAll() nothrowResume all threads but the calling thread for "stop the world" garbage collection runs. This function must be called once for each preceding call to thread_suspendAll before the threads are actual...
fnvoid thread_scanAllType(scope ScanAllThreadsTypeFn scan) nothrowThe main entry point for garbage collection. The supplied delegate will be passed ranges representing both stack and register values.
private fnvoid scanAllTypeImpl(scope ScanAllThreadsTypeFn scan, void * curStackTop) nothrow
fnvoid thread_scanAll(scope ScanAllThreadsFn scan) nothrowThe main entry point for garbage collection. The supplied delegate will be passed ranges representing both stack and register values.
fnvoid onThreadError(string msg) nothrow @nogcA callback for thread errors in D during collections. Since an allocation is not possible a preallocated ThreadError will be used as the Error instance
fnvoid * thread_stackTop() nothrow @nogcReturns the stack top of the currently active stack within the calling thread.
fnvoid * thread_stackBottom() nothrow @nogcReturns the stack bottom of the currently active stack within the calling thread.
fnMutex lowlevelLock() @property nothrow @nogc
fnvoid initLowlevelThreads() @nogc nothrow
fnvoid termLowlevelThreads() @nogc nothrow
fnvoid ll_removeThread(ThreadID tid) nothrow @nogc
fnbool findLowLevelThread(ThreadID tid) nothrow @nogcCheck whether a thread was created by `createLowLevelThread`.

Variables 7

enumvarmutexAlign = __traits(classInstanceAlignment, Mutex)
enumvarmutexClassInstanceSize = __traits(classInstanceSize, Mutex)
varbool multiThreadedFlag
varuint suspendDepth
varsize_t ll_nThreads
varll_ThreadData * ll_pThreads
varvoid[mutexClassInstanceSize] ll_lock