1PTHREAD_ATTR_SETAFFINITY_NP(L3i)nux Programmer's ManPuTaHlREAD_ATTR_SETAFFINITY_NP(3)
2
3
4
6 pthread_attr_setaffinity_np, pthread_attr_getaffinity_np - set/get CPU
7 affinity attribute in thread attributes object
8
10 #define _GNU_SOURCE
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(pthread_attr_t *attr,
16 size_t cpusetsize, cpu_set_t *cpuset);
17
18 Compile and link with -pthread.
19
21 The pthread_attr_setaffinity_np() sets the CPU affinity mask attribute
22 of the thread attributes object referred to by attr to the value speci‐
23 fied in cpuset. This attribute determines the CPU affinity mask of a
24 thread created using the thread attributes object attr.
25
26 The pthread_attr_getaffinity_np() returns the CPU affinity mask
27 attribute of the thread attributes object referred to by attr in the
28 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
39 On success, these functions return 0; on error, they return a non-zero
40 error number.
41
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
56 These functions are provided by glibc since version 2.3.4.
57
59 These functions are non-standard GNU extensions; hence the suffix "_np"
60 (non-portable) in the names.
61
63 In glibc 2.3.3 only, versions of these functions were provided that did
64 not have a cpusetsize argument. Instead the CPU set size given to the
65 underlying system calls was always sizeof(cpu_set_t).
66
68 sched_setaffinity(2), pthread_attr_init(3), pthread_setaffinity_np(3),
69 cpuset(7), pthreads(7)
70
72 This page is part of release 3.22 of the Linux man-pages project. A
73 description of the project, and information about reporting bugs, can
74 be found at http://www.kernel.org/doc/man-pages/.
75
76
77
78Linux 2009-02-01 PTHREAD_ATTR_SETAFFINITY_NP(3)