mtx_destroy, mtx_init — destroy and initialize a mutex
#include <threads.h>
void mtx_destroy(mtx_t *mtx);
int mtx_init(mtx_t *mtx, int type);
[CX]The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1-2024 defers to the ISO C standard.
The mtx_destroy() function shall release any resources used by the mutex pointed to by mtx. A destroyed mutex object can be reinitialized using mtx_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It shall be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex, or a mutex that another thread is attempting to lock, or a mutex that is being used in a cnd_timedwait() or cnd_wait() call by another thread, results in undefined behavior. The behavior is undefined if the value specified by the mtx argument to mtx_destroy() does not refer to an initialized mutex.
The mtx_init() function shall initialize a mutex object with properties indicated by type, whose valid values include:
- mtx_plain
- for a simple non-recursive mutex,
- mtx_timed
- for a non-recursive mutex that supports timeout,
- mtx_plain|mtx_recursive
- for a simple recursive mutex, or
- mtx_timed|mtx_recursive
- for a recursive mutex that supports timeout.
If the mtx_init() function succeeds, it shall set the mutex pointed to by mtx to a value that uniquely identifies the newly initialized mutex. Upon successful initialization, the state of the mutex shall become initialized and unlocked. Attempting to initialize an already initialized mutex results in undefined behavior.
[CX]
See 2.9.9 Synchronization Object Copies and Alternative Mappings for further requirements.
These functions shall not be affected if the calling thread executes a signal handler during the call.
The mtx_destroy() function shall not return a value.
The mtx_init() function shall return thrd_success on success or thrd_error if the request could not be honored.
No errors are defined.
None.
A mutex can be destroyed immediately after it is unlocked. However, since attempting to destroy a locked mutex, or a mutex that another thread is attempting to lock, or a mutex that is being used in a cnd_timedwait() or cnd_wait() call by another thread results in undefined behavior, care must be taken to ensure that no other thread may be referencing the mutex.
These functions are not affected by signal handlers for the reasons stated in XRAT B.2.3 Error Numbers.
None.
XBD <threads.h>
First released in Issue 8. Included for alignment with the ISO/IEC 9899:2018 standard.
return to top of page
紫外线是什么 | 虎属什么五行 | 什么米最贵 | 芙蕖是什么花 | 头上爱出汗是什么原因 |
双侧甲状腺弥漫病变是什么意思 | pdc是什么意思 | 鼻塞流清鼻涕吃什么药 | 喝酒吃海带有什么危害 | 脱线是什么意思 |
鬼什么虎 | 肺炎吃什么药最有效 | 黑色的蛇是什么蛇 | 津液亏虚是什么意思 | 感冒流鼻涕咳嗽吃什么药好 |
太君是什么意思 | 猪头三是什么意思 | 吃什么性功能持久 | 什么人不宜吃海参 | 活动性肺结核是什么意思 |
测血糖挂号挂什么科hcv9jop4ns3r.cn | 墨菲定律讲的是什么hcv9jop2ns7r.cn | 1218是什么星座hcv8jop3ns5r.cn | 肛门瘙痒用什么药膏hcv9jop0ns2r.cn | 上海副市长什么级别hcv9jop3ns9r.cn |
濒死感是什么感觉hcv8jop3ns8r.cn | 小孩积食吃什么药hcv8jop5ns4r.cn | 胃镜预约挂什么科hcv9jop4ns1r.cn | 出国用什么翻译软件好hcv9jop6ns3r.cn | 摸摸唱是什么hcv9jop2ns4r.cn |
什么是汉服helloaicloud.com | 三合局是什么意思bfb118.com | 走路腿软没劲是什么原因引起的hcv8jop1ns3r.cn | 冲正是什么意思hcv9jop5ns1r.cn | 受惊吓吃什么药hcv9jop5ns7r.cn |
百香果的籽有什么功效hcv9jop1ns7r.cn | 采阴补阳是什么意思hcv8jop3ns8r.cn | 50元人民币什么时候发行的hcv9jop1ns5r.cn | 绿茶什么时候喝最好hcv9jop1ns4r.cn | 菜板什么材质的好hcv8jop1ns1r.cn |