> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/pthread/pthread_cond_init.3.md).

# pthread\_cond\_init.3

`pthread_cond_init` — 创建条件变量

## 名称

`pthread_cond_init`

## 库

libpthread

## 概要

```c
#include <pthread.h>

int
pthread_cond_init(pthread_cond_t *restrict cond,
    const pthread_condattr_t *restrict attr);
```

## 描述

`pthread_cond_init` 函数创建一个新的条件变量，其属性由 `attr` 指定。如果 `attr` 为 NULL，则使用默认属性。

## 返回值

如果成功，`pthread_cond_init` 函数将返回零，并将新的条件变量 ID 存入 `cond`；否则将返回一个错误号以指示错误。

## 错误

`pthread_cond_init` 函数将在以下情况失败：

**`[EINVAL]`** 由 `attr` 指定的值无效。

**`[ENOMEM]`** 进程无法分配足够的内存来创建另一个条件变量。

**`[EAGAIN]`** 系统暂时缺乏资源来创建另一个条件变量。

## 参见

[pthread\_cond\_broadcast(3)](/man/pthread/pthread_cond_broadcast.3.md), [pthread\_cond\_destroy(3)](/man/pthread/pthread_cond_destroy.3.md), [pthread\_cond\_signal(3)](/man/pthread/pthread_cond_signal.3.md), [pthread\_cond\_timedwait(3)](/man/pthread/pthread_cond_timedwait.3.md), [pthread\_cond\_wait(3)](/man/pthread/pthread_cond_wait.3.md), [pthread\_condattr(3)](/man/pthread/pthread_condattr.3.md)

## 标准

`pthread_cond_init` 函数符合 ISO/IEC 9945-1:1996 ("POSIX.1") 规范。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/pthread/pthread_cond_init.3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
