core.thread.osthread

The osthread module provides low-level, OS-dependent code for thread creation and management.

Members

Aliases

ThreadID
alias ThreadID = uint

Represents the ID of a thread, as returned by Thread..id. The exact type varies from platform to platform.

getpid
alias getpid = core.sys.posix.unistd.getpid

Returns the process ID of the calling process, which is guaranteed to be unique on the system. This call is always successful.

Classes

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

ThreadError
class ThreadError

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

ThreadException
class ThreadException

Base class for thread exceptions.

ThreadGroup
class ThreadGroup

This class is intended to simplify certain common programming techniques.

Enums

IsMarked
enum IsMarked

Indicates whether an address has been marked by the GC.

ScanType
enum ScanType

Indicates the kind of scan being performed by thread_scanAllType.

Functions

createLowLevelThread
ThreadID createLowLevelThread(void delegate() nothrow dg, uint stacksize = 0, void delegate() nothrow cbDllUnload = null)

Create a thread not under control of the runtime, i.e. TLS module constructors are not run and the GC does not suspend it during a collection.

findLowLevelThread
bool findLowLevelThread(ThreadID tid)

Check whether a thread was created by createLowLevelThread.

joinLowLevelThread
void joinLowLevelThread(ThreadID tid)

Wait for a thread created with createLowLevelThread to terminate.

thread_attachByAddr
Thread thread_attachByAddr(ThreadID addr)
thread_attachByAddrB
Thread thread_attachByAddrB(ThreadID addr, void* bstack)

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.

thread_attachThis
Thread thread_attachThis()

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.

thread_detachByAddr
void thread_detachByAddr(ThreadID addr)
thread_detachInstance
void thread_detachInstance(Thread t)

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.

thread_detachThis
void thread_detachThis()

Deregisters the calling thread from use with the runtime. If this routine is called for a thread which is not registered, the result is undefined.

thread_enterCriticalRegion
void thread_enterCriticalRegion()

Signals that the code following this call is a critical region. Any code in this region must finish running before the calling thread can be suspended by a call to thread_suspendAll.

thread_exitCriticalRegion
void thread_exitCriticalRegion()

Signals that the calling thread is no longer in a critical region. Following a call to this function, the thread can once again be suspended.

thread_inCriticalRegion
bool thread_inCriticalRegion()

Returns true if the current thread is in a critical region; otherwise, false.

thread_init
void thread_init()

Initializes the thread module. This function must be called by the garbage collector on startup and before any other thread routines are called.

thread_isMainThread
bool thread_isMainThread()
thread_joinAll
void 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.

thread_processGCMarks
void thread_processGCMarks(scope IsMarkedDg isMarked)

This routine allows the runtime to process any special per-thread handling for the GC. This is needed for taking into account any memory that is referenced by non-scanned pointers but is about to be freed. That currently means the array append cache.

thread_resumeAll
void thread_resumeAll()

Resume 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 actually resumed.

thread_scanAll
void thread_scanAll(scope ScanAllThreadsFn scan)

The main entry point for garbage collection. The supplied delegate will be passed ranges representing both stack and register values.

thread_scanAllType
void thread_scanAllType(scope ScanAllThreadsTypeFn scan)

The main entry point for garbage collection. The supplied delegate will be passed ranges representing both stack and register values.

thread_setGCSignals
void thread_setGCSignals(int suspendSignalNo, int resumeSignalNo)

Instruct the thread module, when initialized, to use a different set of signals besides SIGUSR1 and SIGUSR2 for suspension and resumption of threads. This function should be called at most once, prior to thread_init(). This function is Posix-only.

thread_setThis
void thread_setThis(Thread t)

Sets 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 Thread.getThis() must return a sensible value in, for example, TLS destructors. In other words, don't touch this unless you know what you're doing.

thread_stackBottom
void* thread_stackBottom()

Returns the stack bottom of the currently active stack within the calling thread.

thread_stackTop
void* thread_stackTop()

Returns the stack top of the currently active stack within the calling thread.

thread_suspendAll
void thread_suspendAll()

Suspend all threads but the calling thread for "stop the world" garbage collection runs. This function may be called multiple times, and must be followed by a matching number of calls to thread_resumeAll before processing is resumed.

thread_term
void thread_term()

Terminates the thread module. No other thread routine may be called afterwards.

Static functions

thread_findByAddr
Thread thread_findByAddr(ThreadID addr)

Search the list of all threads for a thread with the given thread identifier.

Variables

thread_DLLProcessDetaching
bool thread_DLLProcessDetaching;

set during termination of a DLL on Windows, i.e. while executing DllMain(DLL_PROCESS_DETACH)

Meta

License

Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)

Authors

Sean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak

Suggestion Box / Bug Report