1PTHREAD_ATTR_SETAFFINITY_NP(L3i)nux Programmer's ManPuTaHlREAD_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

SYNOPSIS

10       #define _GNU_SOURCE             /* See feature_test_macros(7) */
11       #include <pthread.h>
12
13       int pthread_attr_setaffinity_np(pthread_attr_t *attr,
14                          size_t cpusetsize, const cpu_set_t *cpuset);
15       int pthread_attr_getaffinity_np(const pthread_attr_t *attr,
16                          size_t cpusetsize, cpu_set_t *cpuset);
17
18       Compile and link with -pthread.
19

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

56       These functions are provided by glibc since version 2.3.4.
57

ATTRIBUTES

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

CONFORMING TO

70       These functions are nonstandard GNU extensions; hence the suffix  "_np"
71       (nonportable) in the names.
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

COLOPHON

83       This page is part of release 5.02 of the Linux  man-pages  project.   A
84       description  of  the project, information about reporting bugs, and the
85       latest    version    of    this    page,    can     be     found     at
86       https://www.kernel.org/doc/man-pages/.
87
88
89
90Linux                             2017-09-15    PTHREAD_ATTR_SETAFFINITY_NP(3)
Impressum