2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH pthread_attr_setaffinity_np 3 (date) "Linux man-pages (unreleased)"
9 pthread_attr_setaffinity_np, pthread_attr_getaffinity_np \- set/get
10 CPU affinity attribute in thread attributes object
13 .RI ( libpthread ", " \-lpthread )
16 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
17 .B #include <pthread.h>
19 .BI "int pthread_attr_setaffinity_np(pthread_attr_t *" attr ,
20 .BI " size_t " cpusetsize ", const cpu_set_t *" cpuset );
21 .BI "int pthread_attr_getaffinity_np(const pthread_attr_t *" attr ,
22 .BI " size_t " cpusetsize ", cpu_set_t *" cpuset );
26 .BR pthread_attr_setaffinity_np ()
28 sets the CPU affinity mask attribute of the
29 thread attributes object referred to by
31 to the value specified in
33 This attribute determines the CPU affinity mask
34 of a thread created using the thread attributes object
38 .BR pthread_attr_getaffinity_np ()
40 returns the CPU affinity mask attribute of the thread attributes object
43 in the buffer pointed to by
48 is the length (in bytes) of the buffer pointed to by
50 Typically, this argument would be specified as
51 .IR sizeof(cpu_set_t) .
53 For more details on CPU affinity masks, see
54 .BR sched_setaffinity (2).
55 For a description of a set of macros
56 that can be used to manipulate and inspect CPU sets, see
59 On success, these functions return 0;
60 on error, they return a nonzero error number.
64 .RB ( pthread_attr_setaffinity_np ())
66 specified a CPU that was outside the set supported by the kernel.
67 (The kernel configuration option
69 defines the range of the set supported by the kernel data type
71 used to represent CPU sets.)
72 .\" The raw sched_getaffinity() system call returns the size (in bytes)
73 .\" of the cpumask_t type.
76 .RB ( pthread_attr_getaffinity_np ())
77 A CPU in the affinity mask of the thread attributes object referred to by
79 lies outside the range specified by
82 .IR cpuset / cpusetsize
86 .RB ( pthread_attr_setaffinity_np ())
87 Could not allocate memory.
89 These functions are provided since glibc 2.3.4.
91 For an explanation of the terms used in this section, see
99 Interface Attribute Value
101 .BR pthread_attr_setaffinity_np (),
102 .BR pthread_attr_getaffinity_np ()
103 T} Thread safety MT-Safe
109 These functions are nonstandard GNU extensions;
110 hence the suffix "_np" (nonportable) in the names.
113 versions of these functions were provided that did not have a
116 Instead the CPU set size given to the underlying system calls was always
117 .IR sizeof(cpu_set_t) .
119 .BR sched_setaffinity (2),
120 .BR pthread_attr_init (3),
121 .BR pthread_setaffinity_np (3),