.\" Copyright (c) 2017 The DragonFly Project. All rights reserved. .\" .\" This code is derived from software contributed to The DragonFly Project .\" by Sepherosa Ziehau . .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" 3. Neither the name of The DragonFly Project nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific, prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .Dd January 15, 2017 .Dt PTHREAD_ATTR_SETAFFINITY_NP 2 .Os .Sh NAME .Nm pthread_attr_setaffinity_np , .Nm pthread_attr_getaffinity_np .Nd set and get the thread's CPU affinity mask attribute .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS .In pthread.h .In pthread_np.h .Ft int .Fn pthread_attr_setaffinity_np "pthread_attr_t *attr" "size_t cpusetsize" "const cpu_set_t *mask" .Ft int .Fn pthread_attr_getaffinity_np "const pthread_attr_t *attr" "size_t cpusetsize" "cpu_set_t *mask" .Sh DESCRIPTION The .Fn pthread_attr_setaffinity_np sets the CPU affinity mask of the .Fa attr to the value specified by the .Fa mask . The .Fa cpusetsize is the length (in bytes) of the data pointed to by .Fa mask . Normally this argument would be specified as sizeof(cpu_set_t). The threads created by .Xr pthread_create 3 with the .Fa attr will use the CPU affinity mask of the .Fa attr . .Pp .Fn pthread_attr_getaffinity_np writes the CPU affinity mask of the .Fa attr to the cpu_set_t structure pointed to by .Fa mask . .Pp The cpu_set_t data structure represents a set of CPUs. See .Xr sched_setaffinity 2 for details. .Sh RETURN VALUES If successful, these functions will return zero. Otherwise an error number will be returned to indicate the error. .Sh ERRORS The .Fn pthread_attr_setaffinity_np and .Fn pthread_attr_getaffinity_np will fail if: .Bl -tag -width Er .It Bq Er EFAULT The .Fa mask parameter is outside the process's allocated address space. .It Bq Er EINVAL The .Fa attr parameter is invalid. .It Bq Er EPERM The .Fa mask does not contain a valid CPU. .El .Sh SEE ALSO .Xr pthread_create 3 , .Xr pthread_getaffinity_np 3 , .Xr pthread_setaffinity_np 3 .Sh HISTORY The .Fn pthread_attr_setaffinity_np and .Fn pthread_attr_getaffinity_np functions first appeared in .Dx 4.7 .