1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH PTHREAD_ATTR_SETAFFINITY_NP 3 2010-09-10 "Linux" "Linux Programmer's Manual"
26 pthread_attr_setaffinity_np, pthread_attr_getaffinity_np \- set/get
27 CPU affinity attribute in thread attributes object
30 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
31 .B #include <pthread.h>
33 .BI "int pthread_attr_setaffinity_np(pthread_attr_t *" attr ,
34 .BI " size_t " cpusetsize ", const cpu_set_t *" cpuset );
35 .BI "int pthread_attr_getaffinity_np(pthread_attr_t *" attr ,
36 .BI " size_t " cpusetsize ", cpu_set_t *" cpuset );
38 Compile and link with \fI\-pthread\fP.
41 .BR pthread_attr_setaffinity_np ()
43 sets the CPU affinity mask attribute of the
44 thread attributes object referred to by
46 to the value specified in
48 This attribute determines the CPU affinity mask
49 of a thread created using the thread attributes object
53 .BR pthread_attr_getaffinity_np ()
55 returns the CPU affinity mask attribute of the thread attributes object
58 in the buffer pointed to by
63 is the length (in bytes) of the buffer pointed to by
65 Typically, this argument would be specified as
66 .IR sizeof(cpu_set_t) .
68 For more details on CPU affinity masks, see
69 .BR sched_setaffinity (2).
70 For a description of a set of macros
71 that can be used to manipulate and inspect CPU sets, see
74 On success, these functions return 0;
75 on error, they return a nonzero error number.
79 .RB ( pthread_attr_setaffinity_np ())
81 specified a CPU that was outside the set supported by the kernel.
82 (The kernel configuration option
84 defines the range of the set supported by the kernel data type
86 used to represent CPU sets.)
87 .\" The raw sched_getaffinity() system call returns the size (in bytes)
88 .\" of the cpumask_t type.
91 .RB ( pthread_attr_getaffinity_np ())
92 A CPU in the affinity mask of the thread attributes object referred to by
94 lies outside the range specified by
97 .IR cpuset / cpusetsize
101 .RB ( pthread_attr_setaffinity_np ())
102 Could not allocate memory.
104 These functions are provided by glibc since version 2.3.4.
106 These functions are nonstandard GNU extensions;
107 hence the suffix "_np" (nonportable) in the names.
110 versions of these functions were provided that did not have a
113 Instead the CPU set size given to the underlying system calls was always
114 .IR sizeof(cpu_set_t) .
116 .BR sched_setaffinity (2),
117 .BR pthread_attr_init (3),
118 .BR pthread_setaffinity_np (3),