---
name: "pthread_attr_setschedpolicy"
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_setschedpolicy"
---

# pthread\_attr\_setschedpolicy(3)

set/get scheduling policy attribute in thread attributes object

## NAME

pthread\_attr\_setschedpolicy, pthread\_attr\_getschedpolicy - set/get scheduling policy attribute in thread attributes object

## LIBRARY

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

## SYNOPSIS

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

**int pthread\_attr\_setschedpolicy(pthread\_attr\_t \****attr***, int** *policy***);** **int pthread\_attr\_getschedpolicy(const pthread\_attr\_t \*restrict** *attr***,**                                 **int \*restrict** *policy***);**

## DESCRIPTION

The **pthread\_attr\_setschedpolicy**() function sets the scheduling policy attribute of the thread attributes object referred to by *attr* to the value specified in *policy*. This attribute determines the scheduling policy of a thread created using the thread attributes object *attr*.

The supported values for *policy* are **SCHED\_FIFO**, **SCHED\_RR**, and **SCHED\_OTHER**, with the semantics described in [**sched**(7)](/sched/7.md).

The **pthread\_attr\_getschedpolicy**() returns the scheduling policy attribute of the thread attributes object *attr* in the buffer pointed to by *policy*.

In order for the policy setting made by **pthread\_attr\_setschedpolicy**() 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**.

## RETURN VALUE

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

## ERRORS

**pthread\_attr\_setschedpolicy**() can fail with the following error:

- **EINVAL**

  Invalid value in *policy*.

POSIX.1 also documents an optional **ENOTSUP** error ("attempt was made to set the attribute to an unsupported value") for **pthread\_attr\_setschedpolicy**().

## ATTRIBUTES

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

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

## STANDARDS

POSIX.1-2008.

## HISTORY

glibc 2.0. POSIX.1-2001.

## EXAMPLES

See [**pthread\_setschedparam**(3)](/pthread_setschedparam/3.md).

## SEE ALSO

[**pthread\_attr\_init**(3)](/pthread_attr_init/3.md), [**pthread\_attr\_setinheritsched**(3)](/pthread_attr_setinheritsched/3.md), [**pthread\_attr\_setschedparam**(3)](/pthread_attr_setschedparam/3.md), [**pthread\_create**(3)](/pthread_create/3.md), [**pthread\_setschedparam**(3)](/pthread_setschedparam/3.md), [**pthread\_setschedprio**(3)](/pthread_setschedprio/3.md), [**pthreads**(7)](/pthreads/7.md), [**sched**(7)](/sched/7.md)
