非常教程

C参考手册

线程支持 | Thread support

mtx_init

在头文件<threads.h>中定义

int mtx_init(mtx_t * mutex,int type);

(自C11以来)

使用type创建一个新的互斥对象,指向的对象mutex被设置为新创建的互斥体的标识符。

type 必须具有以下值之一:

  • mtx_plain - 创建一个简单的非递归互斥体。
  • mtx_timed - 创建支持超时的非递归互斥锁。
  • mtx_plain | mtx_recursive - 创建递归互斥。
  • mtx_timed | mtx_recursive - 创建一个支持超时的递归互斥体。

参数

mutex

-

指向要初始化的互斥体的指针

type

-

互斥体的类型

返回值

如果成功则返回 thrd_success,否则返回 thrd_error。

参考

  • C11标准(ISO / IEC 9899:2011):
    • 7.26.4.2 mtx_init 函数(p:381)

扩展内容

| recursive_timed_mutex 的 C ++文档 |

|:----|