System.Threading Namespace

The System.Threading namespace contains basic threading support: threads, mutexes and condition variables. It also contains support for processes and fibers.

Examples

This threadFunction example shows how to execute a function in a separate thread. Main function starts a thread that executes the ThreadFunction function, and waits the thread to end by calling the Join member function of the started thread. A thread function should handle all exceptions. Since all exceptions derive from the Exception class, handling it suffices.

This threadSynchronization example shows how to use LockGuard , RecursiveMutex and a ConditionVariable to synchronize threads. The main function starts first the Run member function of the OutputCollector class in a separate thread. Then it queries the number of cores by calling the HardwareConcurrency function, and starts twice as many output threads. The output threads enqueue message lines by calling the EnqueueLine member function of the OutputCollector . Finally main thread Join s the output threads and the output collector thread.

This third example shows how to transfer exceptions from a separate thread to the main thread.

Namespaces

Fibers

Concepts

public concept Lockable<T>

Classes

public class ConditionVariable
public class LockGuard<Mtx>
public class Mutex
public class Process A class for executing a process and reading and writing its standard output, input and error.
public class RecursiveMutex
public class Thread
public class ThreadingException

Functions

public nothrow int HardwareConcurrency()

Delegates

public delegate void ParameterizedThreadStartFunction(void * param)
public delegate bool Predicate(void * arg)
public delegate void ThreadStartFunction()

Class Delegates

public class delegate void ParameterizedThreadStartMethod(void * param)
public class delegate bool PredicateMethod(void * arg)
public class delegate void ThreadStartMethod()

Enumerated Types

public enum ConditionVariableStatus

Function Details

HardwareConcurrency Function

public nothrow int HardwareConcurrency()

Definition
Line 30 of System.Base/Thread.cm