![]() |
Home | Documentation |
Thread and mutex functions
updated Fri Jan 17 2025 by Robert van Engelen
|
This module defines portable thread and mutex functions. More...
Macros | |
#define | THREAD_TYPE |
Type of a thread (thread ID) | |
#define | THREAD_ID |
The thread ID of self. | |
#define | THREAD_CREATE(tidptr, funcptr, argptr) |
Create a new thread. | |
#define | THREAD_CREATEX(tidptr, funcptr, argptr) |
Create a new joinable thread (Windows only) | |
#define | THREAD_CLOSE(tid) |
Close the thread ID handle created by #THREAD_CREATEX (Windows only) | |
#define | THREAD_DETACH(tid) |
Detach a thread. | |
#define | THREAD_JOIN(tid) |
Join a thread. | |
#define | THREAD_EXIT |
Exit the current thread. | |
#define | THREAD_CANCEL(tid) |
Cancel a thread. | |
#define | MUTEX_TYPE |
Type of a mutex object. | |
#define | MUTEX_INITIALIZER |
Mutex initializer object. | |
#define | MUTEX_SETUP(mx) |
Mutex object initialization. | |
#define | MUTEX_CLEANUP(mx) |
Mutex object finalization. | |
#define | MUTEX_LOCK(mx) |
Mutex object lock. | |
#define | MUTEX_UNLOCK(mx) |
Mutex object unlock. | |
#define | COND_TYPE |
The type of a condition variable. | |
#define | COND_SETUP(cv) |
Condition variable initialization. | |
#define | COND_CLEANUP(cv) |
Condition variable finalization. | |
#define | COND_SIGNAL(cv) |
Condition variable signal operation. | |
#define | COND_WAIT(mx, cv) |
Condition variable wait operation. |
This module defines portable thread and mutex functions.
#define COND_CLEANUP | ( | cv | ) |
Condition variable finalization.
This macro finalizes the specified condition variable.
cv | #COND_TYPE condition variable |
#define COND_SETUP | ( | cv | ) |
Condition variable initialization.
This macro initializes the specified condition variable.
cv | #COND_TYPE condition variable |
#define COND_SIGNAL | ( | cv | ) |
Condition variable signal operation.
This macro signals the specified condition variable.
cv | #COND_TYPE condition variable |
#define COND_TYPE |
The type of a condition variable.
This macro represents a portable condition variable
#define COND_WAIT | ( | mx, | |
cv ) |
Condition variable wait operation.
This macro waits on the specified condition variable and releases the mutex while waiting.
mx | #MUTEX_TYPE mutex object |
cv | #COND_TYPE condition variable |
#define MUTEX_CLEANUP | ( | mx | ) |
Mutex object finalization.
This macro finalizes a mutex object.
mx | #MUTEX_TYPE mutex object |
#define MUTEX_INITIALIZER |
Mutex initializer object.
#define MUTEX_LOCK | ( | mx | ) |
Mutex object lock.
This macro acquires mutex.
mx | #MUTEX_TYPE mutex object |
#define MUTEX_SETUP | ( | mx | ) |
Mutex object initialization.
This macro initializes a mutex object.
To declare and initialize static mutex objects, see #MUTEX_INITIALIZER.
mx | #MUTEX_TYPE mutex object |
#define MUTEX_TYPE |
Type of a mutex object.
This macro represents a portable mutex object type.
To declare and initialize static mutex objects, see #MUTEX_INITIALIZER.
#define MUTEX_UNLOCK | ( | mx | ) |
Mutex object unlock.
This macro releases mutex.
mx | #MUTEX_TYPE mutex object |
#define THREAD_CANCEL | ( | tid | ) |
Cancel a thread.
This macro requests that the specified thread be cancelled.
POSIX threads can be cancelled when currently in a cancellation point, which are certain functions that will terminate the thread when the thread is cancelled.
tid | #THREAD_TYPE thread ID to cancel |
#define THREAD_CLOSE | ( | tid | ) |
Close the thread ID handle created by #THREAD_CREATEX (Windows only)
#define THREAD_CREATE | ( | tidptr, | |
funcptr, | |||
argptr ) |
Create a new thread.
This macro creates a new thread and runs the specified function with the argument parameter passed to this function.
tidptr | pointer to #THREAD_TYPE thread ID to assign |
funcptr | function to run by the new thread |
argptr | the argument (a pointer) to pass to the function when called |
#define THREAD_CREATEX | ( | tidptr, | |
funcptr, | |||
argptr ) |
Create a new joinable thread (Windows only)
On Windows platforms #THREAD_CREATE uses _beginthread which returns a thread ID handle that cannot be joined. To join a thread use THREAD_CREATEX(&tid, func, arg) then #THREAD_JOIN. Don't forget to THREAD_CLOSE(tid) afterwards.
#define THREAD_DETACH | ( | tid | ) |
Detach a thread.
This macro detaches the specified thread. A detached thread cannot be joined back with the thread that created it. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread.
This macro has no effect on Windows platforms, see #THREAD_CREATE.
tid | #THREAD_TYPE thread ID to detach |
#define THREAD_EXIT |
Exit the current thread.
This macro terminates the current thread.
#define THREAD_ID |
The thread ID of self.
This macro represents the current thread ID, i.e. self.
#define THREAD_JOIN | ( | tid | ) |
Join a thread.
This macro waits for the termination of the specified thread to join it.
This macro requires #THREAD_CREATEX and #THREAD_CLOSE on Windows plaforms.
tid | #THREAD_TYPE thread ID to join |
#define THREAD_TYPE |
Type of a thread (thread ID)
This macro represents a portable thread ID type.