The osthread module provides low-level, OS-dependent code for thread creation and management.
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.
Initializes a thread object which is associated with a static D function.
void function() fn
| The thread function. |
size_t sz
| The stack size for this thread. |
Initializes a thread object which is associated with a dynamic D function.
void delegate() dg
| The thread function. |
size_t sz
| The stack size for this thread. |
Provides a reference to the calling thread.
Starts the thread and invokes the function or delegate passed upon construction.
Waits for this thread to complete. If the thread terminated as the result of an unhandled exception, this exception will be rethrown.
bool rethrow
| Rethrow any unhandled exception which may have caused this thread to terminate. |
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.
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.
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.
Gets the scheduling priority for the associated thread.
Sets the scheduling priority for the associated thread.
int val
| The new scheduling priority of this thread. |
Tests whether this thread is running.
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.
Duration val
| The minimum duration the calling thread should be suspended. |
Thread.sleep( dur!("msecs")( 50 ) ); // sleep for 50 milliseconds
Thread.sleep( dur!("seconds")( 5 ) ); // sleep for 5 seconds
Forces a context switch to occur away from the calling thread.
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.
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.
Returns the process ID of the calling process, which is guaranteed to be unique on the system. This call is always successful.
writefln("Current process id: %s", getpid());
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.
Initializes the thread module. This function must be called by the garbage collector on startup and before any other thread routines are called.
Terminates the thread module. No other thread routine may be called afterwards.
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.
void delegate() nothrow dg
| delegate to execute in the created thread. |
uint stacksize
| size of the stack of the created thread. The default of 0 will select the platform-specific default size. |
void delegate() nothrow cbDllUnload
| Windows only: if running in a dynamically loaded DLL, this delegate will be called if the DLL is supposed to be unloaded, but the thread is still running. The thread must be terminated via joinLowLevelThread by the callback. |
ThreadID.init is returned.Wait for a thread created with createLowLevelThread to terminate.
ThreadID tid
| the thread ID returned by createLowLevelThread. |
© 1999–2021 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/core_thread_osthread.html