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

# pthread\_getconcurrency.3

`pthread_getconcurrency` — 获取或设置并发级别

## 名称

`pthread_getconcurrency`, `pthread_setconcurrency`

## 库

libpthread

## 概要

```c
#include <pthread.h>

int
pthread_getconcurrency(void);

int
pthread_setconcurrency(int new_level);
```

## 描述

`pthread_setconcurrency` 函数允许应用程序向线程实现告知其期望的并发级别 `new_level`。该函数调用后实现所提供的实际并发级别未定义。如果 `new_level` 为零，实现将自行决定维持并发级别，如同从未调用过 `pthread_setconcurrency`。`pthread_getconcurrency` 函数返回先前调用 `pthread_setconcurrency` 函数所设置的值。如果先前未调用过 `pthread_setconcurrency` 函数，该函数返回零以指示实现正在自行维持并发级别。应用程序调用 `pthread_setconcurrency` 时，是在向实现告知其期望的并发级别。实现仅将其作为提示，而非要求。

## 返回值

如果成功，`pthread_setconcurrency` 函数返回零；否则返回一个错误号以指示错误。`pthread_getconcurrency` 函数总是返回先前调用 `pthread_setconcurrency` 所设置的并发级别。如果从未调用过 `pthread_setconcurrency` 函数，`pthread_getconcurrency` 返回零。

## 错误

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

**`[EINVAL]`** `new_level` 指定的值为负数。

**`[EAGAIN]`** `new_level` 指定的值将导致超出系统资源限制。

## 应用程序使用说明

使用这些函数会改变应用程序所依赖的底层并发状态。建议库开发者不要使用 `pthread_getconcurrency` 和 `pthread_setconcurrency` 函数，因为其使用可能与应用程序对这些函数的使用产生冲突。

## 标准

`pthread_getconcurrency` 和 `pthread_setconcurrency` 函数符合 -susv2 规范。


---

# 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_getconcurrency.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.
