Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

API reference / Windows

Thread class

Owns a Win32 thread handle and closes it on destruction.

Use
import ThinkMeta.ConcurrentTasks.Windows.Thread;
Namespace
ThinkMeta::ConcurrentTasks::Windows

Syntax

class Thread

Remarks

Owning the handle does not control the thread: destroying the object leaves the thread running. Members report failures as ErrorCode. Members that act on the thread require a handle (asserted in debug builds). Use one object from one thread at a time; the thread APIs it wraps are thread-safe.

See also

ConvenienceThread

Constructors

Thread

Constructs an object without a handle.

Syntax

Thread() noexcept = default;

Takes over the handle of other.

Syntax

Thread(Thread&& other) noexcept;

Parameters

otherThread&&
Left without a handle.

~Thread

Closes the handle, if any.

Syntax

~Thread() noexcept;

Remarks

The thread itself keeps running.

Methods

operator=

Takes over the handle of other.

Syntax

Thread& operator=(Thread&& other) noexcept;

Parameters

otherThread&&
Left without a handle.

Return value

Type: Thread&

This object.

Remarks

A handle this object held before is closed first.

IsValid

Returns whether the object holds a handle.

Syntax

bool IsValid() const noexcept;

Return value

Type: bool

true if a handle is held; otherwise false.

Open

Opens an existing thread by id (OpenThread).

Syntax

static ErrorCode Open(
    DWORD desiredAccess,
    BOOL inheritHandle,
    DWORD threadId,
    Thread& thread
) noexcept;

Parameters

desiredAccessDWORD
Access rights the handle gets, e.g. THREAD_QUERY_LIMITED_INFORMATION or THREAD_ALL_ACCESS.
inheritHandleBOOL
TRUE to let child processes inherit the handle.
threadIdDWORD
Id of the thread to open.
threadThread&
Receives the handle; a handle it held before is closed.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

Close

Create

Creates a thread in this process (CreateThread) and keeps its handle.

Syntax

ErrorCode Create(
    SECURITY_ATTRIBUTES* threadAttributes,
    SIZE_T stackSize,
    PTHREAD_START_ROUTINE startAddress,
    void* parameter,
    DWORD creationFlags,
    DWORD* threadId
) noexcept;

Parameters

threadAttributesSECURITY_ATTRIBUTES*
Security descriptor and inheritance of the handle; nullptr: default security, not inheritable.
stackSizeSIZE_T
Initial stack size in bytes; 0: the executable's default.
startAddressPTHREAD_START_ROUTINE
The thread function; required.
parametervoid*
Passed unchanged to startAddress; may be nullptr.
creationFlagsDWORD
0 to run at once, CREATE_SUSPENDED to start suspended (see Resume), STACK_SIZE_PARAM_IS_A_RESERVATION to reserve rather than commit stackSize.
threadIdDWORD*
Receives the new thread's id; may be nullptr.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

The object must not hold a handle yet. The new thread runs startAddress as a plain OS thread, not as a task.

See also

CreateRemote, Close

CreateRemote

Creates a thread in another process (CreateRemoteThread).

Syntax

ErrorCode CreateRemote(
    HANDLE process,
    SECURITY_ATTRIBUTES* threadAttributes,
    SIZE_T stackSize,
    PTHREAD_START_ROUTINE startAddress,
    void* parameter,
    DWORD creationFlags,
    DWORD* threadId
) noexcept;

Parameters

processHANDLE
Handle of the target process with PROCESS_CREATE_THREAD, PROCESS_QUERY_INFORMATION, PROCESS_VM_OPERATION, PROCESS_VM_WRITE and PROCESS_VM_READ access; borrowed.
threadAttributesSECURITY_ATTRIBUTES*
Security descriptor and inheritance of the handle; nullptr: default security, not inheritable.
stackSizeSIZE_T
Initial stack size in bytes; 0: the executable's default.
startAddressPTHREAD_START_ROUTINE
The thread function, an address in the target process; required.
parametervoid*
Passed unchanged to startAddress; may be nullptr.
creationFlagsDWORD
0 to run at once, CREATE_SUSPENDED to start suspended, STACK_SIZE_PARAM_IS_A_RESERVATION to reserve rather than commit stackSize.
threadIdDWORD*
Receives the new thread's id; may be nullptr.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

The object must not hold a handle yet.

See also

Create

Creates a thread in another process (CreateRemoteThreadEx).

Syntax

ErrorCode CreateRemote(
    HANDLE process,
    SECURITY_ATTRIBUTES* threadAttributes,
    SIZE_T stackSize,
    PTHREAD_START_ROUTINE startAddress,
    void* parameter,
    DWORD creationFlags,
    LPPROC_THREAD_ATTRIBUTE_LIST attributeList,
    DWORD* threadId
) noexcept;

Parameters

processHANDLE
Handle of the target process with PROCESS_CREATE_THREAD, PROCESS_QUERY_INFORMATION, PROCESS_VM_OPERATION, PROCESS_VM_WRITE and PROCESS_VM_READ access; borrowed.
threadAttributesSECURITY_ATTRIBUTES*
Security descriptor and inheritance of the handle; nullptr: default security, not inheritable.
stackSizeSIZE_T
Initial stack size in bytes; 0: the executable's default.
startAddressPTHREAD_START_ROUTINE
The thread function, an address in the target process; required.
parametervoid*
Passed unchanged to startAddress; may be nullptr.
creationFlagsDWORD
0 to run at once, CREATE_SUSPENDED to start suspended, STACK_SIZE_PARAM_IS_A_RESERVATION to reserve rather than commit stackSize.
attributeListLPPROC_THREAD_ATTRIBUTE_LIST
Extended attributes of the new thread (InitializeProcThreadAttributeList); may be nullptr.
threadIdDWORD*
Receives the new thread's id; may be nullptr.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

The object must not hold a handle yet.

Close

Closes the handle (CloseHandle).

Syntax

ErrorCode Close() noexcept;

Return value

Type: ErrorCode

Error::Success (0) on success, also if there is no handle; otherwise the Win32 error code.

Remarks

On failure the object keeps the handle.

Current

Returns the calling thread's pseudo-handle (GetCurrentThread).

Syntax

static Thread Current() noexcept;

Return value

Type: Thread

An object holding the pseudo-handle.

Remarks

Valid only on the calling thread; needs no closing (CloseHandle on it does nothing).

See also

CurrentId

CurrentId

Returns the calling thread's id (GetCurrentThreadId).

Syntax

static DWORD CurrentId() noexcept;

Return value

Type: DWORD

The id, unique system-wide while the thread exists.

GetExitCode

Gets the exit code (GetExitCodeThread).

Syntax

ErrorCode GetExitCode(DWORD& exitCode) noexcept;

Parameters

exitCodeDWORD&
Receives the exit code; STILL_ACTIVE while the thread runs.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

SetAffinityMask

Sets the affinity mask (SetThreadAffinityMask).

Syntax

ErrorCode SetAffinityMask(DWORD_PTR& affinityMask) noexcept;

Parameters

affinityMaskDWORD_PTR&
In: the new mask within the thread's processor group. Out, on success: the previous mask.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

SetGroupAffinity

GetGroupAffinity

Gets processor group and affinity (GetThreadGroupAffinity).

Syntax

ErrorCode GetGroupAffinity(GROUP_AFFINITY& groupAffinity) noexcept;

Parameters

groupAffinityGROUP_AFFINITY&
Receives the thread's processor group and affinity mask in it.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

SetGroupAffinity

SetGroupAffinity

Sets processor group and affinity (SetThreadGroupAffinity).

Syntax

ErrorCode SetGroupAffinity(
    const GROUP_AFFINITY& groupAffinity,
    GROUP_AFFINITY* previousGroupAffinity = nullptr
) noexcept;

Parameters

groupAffinityconst GROUP_AFFINITY&
The new processor group and a nonzero affinity mask within it; the reserved fields must be 0.
previousGroupAffinityGROUP_AFFINITY*
Receives the previous one; may be nullptr.Default: nullptr

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

GetGroupAffinity

GetId

Gets the thread id (GetThreadId).

Syntax

ErrorCode GetId(DWORD& id) noexcept;

Parameters

idDWORD&
Receives the thread's id; 0 on failure.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

GetIdealProcessor

Gets the ideal processor (GetThreadIdealProcessorEx).

Syntax

ErrorCode GetIdealProcessor(PROCESSOR_NUMBER& idealProcessor) noexcept;

Parameters

idealProcessorPROCESSOR_NUMBER&
Receives the processor group and number of the ideal processor.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

SetIdealProcessor

SetIdealProcessor

Sets the ideal processor in the thread's group (SetThreadIdealProcessor).

Syntax

ErrorCode SetIdealProcessor(DWORD& idealProcessor) noexcept;

Parameters

idealProcessorDWORD&
In: the new processor (MAXIMUM_PROCESSORS only queries). Out, on success: the previous one.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

GetIdealProcessor

Sets the ideal processor in any group (SetThreadIdealProcessorEx).

Syntax

ErrorCode SetIdealProcessor(
    PROCESSOR_NUMBER& idealProcessor,
    PROCESSOR_NUMBER* previousIdealProcessor = nullptr
) noexcept;

Parameters

idealProcessorPROCESSOR_NUMBER&
Processor group and number of the new ideal processor.
previousIdealProcessorPROCESSOR_NUMBER*
Receives the previous one; may be nullptr.Default: nullptr

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

GetIoPendingFlag

Gets whether I/O requests are pending (GetThreadIOPendingFlag).

Syntax

ErrorCode GetIoPendingFlag(BOOL& ioIsPending) noexcept;

Parameters

ioIsPendingBOOL&
Receives TRUE if the thread has I/O requests pending, else FALSE.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

GetPriority

Gets the thread priority (GetThreadPriority).

Syntax

ErrorCode GetPriority(int& priority) noexcept;

Parameters

priorityint&
Receives the priority, e.g. THREAD_PRIORITY_NORMAL.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

SetPriority

SetPriority

Sets the thread priority (SetThreadPriority).

Syntax

ErrorCode SetPriority(int priority) noexcept;

Parameters

priorityint
The new priority, e.g. THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_HIGHEST or THREAD_MODE_BACKGROUND_BEGIN.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

GetPriority

GetPriorityBoost

Gets whether priority boosting is disabled (GetThreadPriorityBoost).

Syntax

ErrorCode GetPriorityBoost(BOOL& disablePriorityBoost) noexcept;

Parameters

disablePriorityBoostBOOL&
Receives TRUE if boosting is disabled, FALSE if enabled.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

SetPriorityBoost

SetPriorityBoost

Disables or enables dynamic priority boosting (SetThreadPriorityBoost).

Syntax

ErrorCode SetPriorityBoost(BOOL disablePriorityBoost) noexcept;

Parameters

disablePriorityBoostBOOL
TRUE disables boosting, FALSE enables it.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

See also

GetPriorityBoost

GetTimes

Gets the thread's times (GetThreadTimes).

Syntax

ErrorCode GetTimes(
    FILETIME& creationTime,
    FILETIME& exitTime,
    FILETIME& kernelTime,
    FILETIME& userTime
) noexcept;

Parameters

creationTimeFILETIME&
Receives the creation time (UTC, 100-ns units since 1601-01-01).
exitTimeFILETIME&
Receives the exit time in the same format; undefined while the thread runs.
kernelTimeFILETIME&
Receives the CPU time spent in kernel mode, in 100-ns units.
userTimeFILETIME&
Receives the CPU time spent in user mode, in 100-ns units.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

Creation and exit time, kernel and user CPU time.

See also

QueryCycleTime

QueryCycleTime

Gets the CPU clock cycles the thread has used (QueryThreadCycleTime).

Syntax

ErrorCode QueryCycleTime(ULONG64& cycleTime) noexcept;

Parameters

cycleTimeULONG64&
Receives the cycle count, in user and kernel mode together.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Suspend

Suspends the OS thread (SuspendThread).

Syntax

ErrorCode Suspend(DWORD& previousSuspendCount) noexcept;

Parameters

previousSuspendCountDWORD&
Receives the previous suspend count.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

Not a task suspension; meant for debuggers and tools.

See also

Resume

Suspends the OS thread (SuspendThread).

Syntax

ErrorCode Suspend() noexcept;

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

Discards the previous suspend count.

See also

Resume

Resume

Decrements the suspend count (ResumeThread).

Syntax

ErrorCode Resume(DWORD& previousSuspendCount) noexcept;

Parameters

previousSuspendCountDWORD&
Receives the previous suspend count.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

The thread runs again when the count reaches zero.

See also

Suspend

Decrements the suspend count (ResumeThread).

Syntax

ErrorCode Resume() noexcept;

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

Discards the previous suspend count.

See also

Suspend

Terminate

Kills the thread (TerminateThread).

Syntax

ErrorCode Terminate(DWORD exitCode) noexcept;

Parameters

exitCodeDWORD
The exit code the thread ends with (see GetExitCode).

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

Dangerous: no cleanup, held locks stay held.

Wait

Waits until the thread exits (WaitForSingleObject).

Syntax

ErrorCode Wait(DWORD milliseconds, DWORD& event) noexcept;

Parameters

millisecondsDWORD
Timeout in milliseconds; INFINITE waits without one.
eventDWORD&
Receives the wait result (WAIT_OBJECT_0, WAIT_TIMEOUT, ...).

Return value

Type: ErrorCode

Error::Success unless the wait failed, so a timeout is Success too.

Remarks

Blocks the whole OS thread: called from a task it blocks the scheduler thread.

QueueUserApc

Queues a user-mode APC to the thread (QueueUserAPC).

Syntax

ErrorCode QueueUserApc(PAPCFUNC apcFunction, ULONG_PTR data) noexcept;

Parameters

apcFunctionPAPCFUNC
The function to run on the thread; required.
dataULONG_PTR
Passed unchanged to apcFunction.

Return value

Type: ErrorCode

Error::Success (0) on success; otherwise the Win32 error code.

Remarks

The APC runs when the thread waits alertably.

Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).