1pthread_attr_setaffinity_np(L3i)brary Functions Manupatlhread_attr_setaffinity_np(3)
2
3
4

NAME

6       pthread_attr_setaffinity_np,  pthread_attr_getaffinity_np - set/get CPU
7       affinity attribute in thread attributes object
8

LIBRARY

10       POSIX threads library (libpthread, -lpthread)
11

SYNOPSIS

13       #define _GNU_SOURCE             /* See feature_test_macros(7) */
14       #include <pthread.h>
15
16       int pthread_attr_setaffinity_np(pthread_attr_t *attr,
17                          size_t cpusetsize, const cpu_set_t *cpuset);
18       int pthread_attr_getaffinity_np(const pthread_attr_t *attr,
19                          size_t cpusetsize, cpu_set_t *cpuset);
20

DESCRIPTION

22       The pthread_attr_setaffinity_np() function sets the CPU  affinity  mask
23       attribute  of  the  thread attributes object referred to by attr to the
24       value specified in cpuset.  This attribute determines the CPU  affinity
25       mask of a thread created using the thread attributes object attr.
26
27       The  pthread_attr_getaffinity_np()  function  returns  the CPU affinity
28       mask attribute of the thread attributes object referred to by  attr  in
29       the buffer pointed to by cpuset.
30
31       The  argument cpusetsize is the length (in bytes) of the buffer pointed
32       to  by  cpuset.   Typically,  this  argument  would  be  specified   as
33       sizeof(cpu_set_t).
34
35       For  more details on CPU affinity masks, see sched_setaffinity(2).  For
36       a description of a set of macros that can be used to manipulate and in‐
37       spect CPU sets, see CPU_SET(3).
38

RETURN VALUE

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

ERRORS

44       EINVAL (pthread_attr_setaffinity_np()) cpuset specified a CPU that  was
45              outside the set supported by the kernel.  (The kernel configura‐
46              tion option CONFIG_NR_CPUS defines the range  of  the  set  sup‐
47              ported by the kernel data type used to represent CPU sets.)
48
49       EINVAL (pthread_attr_getaffinity_np())  A  CPU  in the affinity mask of
50              the thread attributes object referred to by  attr  lies  outside
51              the  range  specified  by cpusetsize (i.e., cpuset/cpusetsize is
52              too small).
53
54       ENOMEM (pthread_attr_setaffinity_np()) Could not allocate memory.
55

ATTRIBUTES

57       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
58       tributes(7).
59
60       ┌────────────────────────────────────────────┬───────────────┬─────────┐
61Interface                                   Attribute     Value   
62       ├────────────────────────────────────────────┼───────────────┼─────────┤
63pthread_attr_setaffinity_np(),              │ Thread safety │ MT-Safe │
64pthread_attr_getaffinity_np()               │               │         │
65       └────────────────────────────────────────────┴───────────────┴─────────┘
66

STANDARDS

68       GNU; hence the suffix "_np" (nonportable) in the names.
69

HISTORY

71       glibc 2.3.4.
72

NOTES

74       In glibc 2.3.3 only, versions of these functions were provided that did
75       not  have a cpusetsize argument.  Instead the CPU set size given to the
76       underlying system calls was always sizeof(cpu_set_t).
77

SEE ALSO

79       sched_setaffinity(2), pthread_attr_init(3),  pthread_setaffinity_np(3),
80       cpuset(7), pthreads(7)
81
82
83
84Linux man-pages 6.04              2023-03-30    pthread_attr_setaffinity_np(3)
Impressum