> 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_mutex_consistent.3.md).

# pthread\_mutex\_consistent.3

`pthread_mutex_consistent` — 将 robust mutex 所保护的状态标记为一致

## 名称

`pthread_mutex_consistent`

## 库

libpthread

## 概要

```c
#include <pthread.h>

int
pthread_mutex_consistent(pthread_mutex_t *mutex);
```

## 描述

如果持有 robust mutex 的线程所在进程在持有该 mutex 时终止，mutex 将进入不一致状态，下一个获取该 mutex 锁的线程会通过返回值 `EOWNERDEAD` 收到该状态的通知。此时，在状态被标记为一致之前，mutex 无法正常使用。

`pthread_mutex_consistent` 在 `mutex` 参数指向处于不一致状态的已初始化 robust mutex 时调用，会将该 mutex 重新标记为一致。随后通过 `pthread_mutex_unlock` 或其他方式解锁该 mutex，将允许其他等待者加锁。

如果处于不一致状态的 mutex 在解锁前未通过调用 `pthread_mutex_consistent` 标记为一致，后续尝试加锁 `mutex` 的操作将由加锁函数返回 `ENOTRECOVERABLE` 错误。

## 返回值

如果成功，`pthread_mutex_consistent` 将返回零，否则返回一个错误编号以指示错误。

## 错误

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

**`[EINVAL]`** 由 `mutex` 参数指向的 mutex 不是 robust mutex，或者未处于不一致状态。

## 参见

[pthread\_mutex\_init(3)](/man/pthread/pthread_mutex_init.3.md), [pthread\_mutex\_lock(3)](/man/pthread/pthread_mutex_lock.3.md), [pthread\_mutex\_unlock(3)](/man/pthread/pthread_mutex_unlock.3.md), pthread\_mutexattr\_setrobust(3)

## 标准

`pthread_mutex_consistent` 函数遵循 IEEE Std 1003.1-2008 (“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_mutex_consistent.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.
