---
name: "pthread_attr_getscope"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/pthread_attr_setscope"
---

# pthread\_attr\_getscope(3)

set/get contention scope attribute in thread attributes object

Part of [pthread\_attr\_setscope(3)](/pthread_attr_setscope/3.md).

## NAME

pthread\_attr\_setscope, pthread\_attr\_getscope - set/get contention scope attribute in thread attributes object

## LIBRARY

POSIX threads library (*libpthread*, *-lpthread*)

## SYNOPSIS

```
#include <pthread.h>
```

**int pthread\_attr\_setscope(pthread\_attr\_t \****attr***, int** *scope***);** **int pthread\_attr\_getscope(const pthread\_attr\_t \*restrict** *attr***,**                           **int \*restrict** *scope***);**

## DESCRIPTION

The **pthread\_attr\_setscope**() function sets the contention scope attribute of the thread attributes object referred to by *attr* to the value specified in *scope*. The contention scope attribute defines the set of threads against which a thread competes for resources such as the CPU. POSIX.1 specifies two possible values for *scope*:

- **PTHREAD\_SCOPE\_SYSTEM**

  The thread competes for resources with all other threads in all processes on the system that are in the same scheduling allocation domain (a group of one or more processors). **PTHREAD\_SCOPE\_SYSTEM** threads are scheduled relative to one another according to their scheduling policy and priority.

- **PTHREAD\_SCOPE\_PROCESS**

  The thread competes for resources with all other threads in the same process that were also created with the **PTHREAD\_SCOPE\_PROCESS** contention scope. **PTHREAD\_SCOPE\_PROCESS** threads are scheduled relative to other threads in the process according to their scheduling policy and priority. POSIX.1 leaves it unspecified how these threads contend with other threads in other process on the system or with other threads in the same process that were created with the **PTHREAD\_SCOPE\_SYSTEM** contention scope.

POSIX.1 requires that an implementation support at least one of these contention scopes. Linux supports **PTHREAD\_SCOPE\_SYSTEM**, but not **PTHREAD\_SCOPE\_PROCESS**.

On systems that support multiple contention scopes, then, in order for the parameter setting made by **pthread\_attr\_setscope**() to have effect when calling [**pthread\_create**(3)](/pthread_create/3.md), the caller must use [**pthread\_attr\_setinheritsched**(3)](/pthread_attr_setinheritsched/3.md) to set the inherit-scheduler attribute of the attributes object *attr* to **PTHREAD\_EXPLICIT\_SCHED**.

The **pthread\_attr\_getscope**() function returns the contention scope attribute of the thread attributes object referred to by *attr* in the buffer pointed to by *scope*.

## RETURN VALUE

On success, these functions return 0; on error, they return a nonzero error number.

## ERRORS

**pthread\_attr\_setscope**() can fail with the following errors:

- **EINVAL**

  An invalid value was specified in *scope*.

- **ENOTSUP**

  *scope* specified the value **PTHREAD\_SCOPE\_PROCESS**, which is not supported on Linux.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **pthread\_attr\_setscope**(), **pthread\_attr\_getscope**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008.

## HISTORY

POSIX.1-2001.

## NOTES

The **PTHREAD\_SCOPE\_SYSTEM** contention scope typically indicates that a user-space thread is bound directly to a single kernel-scheduling entity. This is the case on Linux for the obsolete LinuxThreads implementation and the modern NPTL implementation, which are both 1:1 threading implementations.

POSIX.1 specifies that the default contention scope is implementation-defined.

## SEE ALSO

[**pthread\_attr\_init**(3)](/pthread_attr_init/3.md), [**pthread\_attr\_setaffinity\_np**(3)](/pthread_attr_setaffinity_np/3.md), [**pthread\_attr\_setinheritsched**(3)](/pthread_attr_setinheritsched/3.md), [**pthread\_attr\_setschedparam**(3)](/pthread_attr_setschedparam/3.md), [**pthread\_attr\_setschedpolicy**(3)](/pthread_attr_setschedpolicy/3.md), [**pthread\_create**(3)](/pthread_create/3.md), [**pthreads**(7)](/pthreads/7.md)
