1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH PTHREAD_ATTR_SETAFFINITY_NP 3 2021-03-22 "Linux" "Linux Programmer's Manual"
8 pthread_attr_setaffinity_np, pthread_attr_getaffinity_np \- set/get
9 CPU affinity attribute in thread attributes object
12 .RI ( libpthread ", " \-lpthread )
15 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .B #include <pthread.h>
18 .BI "int pthread_attr_setaffinity_np(pthread_attr_t *" attr ,
19 .BI " size_t " cpusetsize ", const cpu_set_t *" cpuset );
20 .BI "int pthread_attr_getaffinity_np(const pthread_attr_t *" attr ,
21 .BI " size_t " cpusetsize ", cpu_set_t *" cpuset );
25 .BR pthread_attr_setaffinity_np ()
27 sets the CPU affinity mask attribute of the
28 thread attributes object referred to by
30 to the value specified in
32 This attribute determines the CPU affinity mask
33 of a thread created using the thread attributes object
37 .BR pthread_attr_getaffinity_np ()
39 returns the CPU affinity mask attribute of the thread attributes object
42 in the buffer pointed to by
47 is the length (in bytes) of the buffer pointed to by
49 Typically, this argument would be specified as
50 .IR sizeof(cpu_set_t) .
52 For more details on CPU affinity masks, see
53 .BR sched_setaffinity (2).
54 For a description of a set of macros
55 that can be used to manipulate and inspect CPU sets, see
58 On success, these functions return 0;
59 on error, they return a nonzero error number.
63 .RB ( pthread_attr_setaffinity_np ())
65 specified a CPU that was outside the set supported by the kernel.
66 (The kernel configuration option
68 defines the range of the set supported by the kernel data type
70 used to represent CPU sets.)
71 .\" The raw sched_getaffinity() system call returns the size (in bytes)
72 .\" of the cpumask_t type.
75 .RB ( pthread_attr_getaffinity_np ())
76 A CPU in the affinity mask of the thread attributes object referred to by
78 lies outside the range specified by
81 .IR cpuset / cpusetsize
85 .RB ( pthread_attr_setaffinity_np ())
86 Could not allocate memory.
88 These functions are provided by glibc since version 2.3.4.
90 For an explanation of the terms used in this section, see
98 Interface Attribute Value
100 .BR pthread_attr_setaffinity_np (),
101 .BR pthread_attr_getaffinity_np ()
102 T} Thread safety MT-Safe
108 These functions are nonstandard GNU extensions;
109 hence the suffix "_np" (nonportable) in the names.
112 versions of these functions were provided that did not have a
115 Instead the CPU set size given to the underlying system calls was always
116 .IR sizeof(cpu_set_t) .
118 .BR sched_setaffinity (2),
119 .BR pthread_attr_init (3),
120 .BR pthread_setaffinity_np (3),