1.\" $NetBSD: pthread_attr.3,v 1.5 2007/03/21 18:53:32 ad Exp $ 2.\" 3.\" Copyright (c) 2002 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. Neither the name of The NetBSD Foundation nor the names of its 14.\" contributors may be used to endorse or promote products derived 15.\" from this software without specific prior written permission. 16.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26.\" POSSIBILITY OF SUCH DAMAGE. 27.\" 28.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. 29.\" All rights reserved. 30.\" 31.\" Redistribution and use in source and binary forms, with or without 32.\" modification, are permitted provided that the following conditions 33.\" are met: 34.\" 1. Redistributions of source code must retain the above copyright 35.\" notice(s), this list of conditions and the following disclaimer as 36.\" the first lines of this file unmodified other than the possible 37.\" addition of one or more copyright notices. 38.\" 2. Redistributions in binary form must reproduce the above copyright 39.\" notice(s), this list of conditions and the following disclaimer in 40.\" the documentation and/or other materials provided with the 41.\" distribution. 42.\" 43.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 44.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 46.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 47.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 48.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 49.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 50.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 51.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 52.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 53.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54.\" 55.\" $FreeBSD: src/lib/libpthread/man/pthread_attr.3,v 1.11 2002/09/16 19:29:28 mini Exp $ 56.Dd March 21, 2007 57.Dt PTHREAD_ATTR 3 58.Os 59.Sh NAME 60.Nm pthread_attr_init , 61.Nm pthread_attr_destroy , 62./" .Nm pthread_attr_setstacksize , 63./" .Nm pthread_attr_getstacksize , 64./" .Nm pthread_attr_setguardsize , 65./" .Nm pthread_attr_getguardsize , 66./" .Nm pthread_attr_setstackaddr , 67./" .Nm pthread_attr_getstackaddr , 68.Nm pthread_attr_setdetachstate , 69.Nm pthread_attr_getdetachstate , 70./" .Nm pthread_attr_setinheritsched , 71./" .Nm pthread_attr_getinheritsched , 72.Nm pthread_attr_setschedparam , 73.Nm pthread_attr_getschedparam 74./" .Nm pthread_attr_setschedpolicy , 75./" .Nm pthread_attr_getschedpolicy , 76./" .Nm pthread_attr_setscope , 77./" .Nm pthread_attr_getscope 78.Nd thread attribute operations 79.Sh LIBRARY 80.Lb libpthread 81.Sh SYNOPSIS 82.In pthread.h 83.Ft int 84.Fn pthread_attr_init "pthread_attr_t *attr" 85.Ft int 86.Fn pthread_attr_destroy "pthread_attr_t *attr" 87./" .Ft int 88./" .Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize" 89./" .Ft int 90./" .Fn pthread_attr_getstacksize "const pthread_attr_t * restrict attr" "size_t * restrict stacksize" 91./" .Ft int 92./" .Fn pthread_attr_setguardsize "pthread_attr_t *attr" "size_t guardsize" 93./" .Ft int 94./" .Fn pthread_attr_getguardsize "const pthread_attr_t * restrict attr" "size_t * restrict guardsize" 95./" .Ft int 96./" .Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr" 97./" .Ft int 98./" .Fn pthread_attr_getstackaddr "const pthread_attr_t * restrict attr" "void ** restrict stackaddr" 99.Ft int 100.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate" 101.Ft int 102.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate" 103./" .Ft int 104./" .Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched" 105./" .Ft int 106./" .Fn pthread_attr_getinheritsched "const pthread_attr_t * restrict attr" "int * restrict inheritsched" 107.Ft int 108.Fn pthread_attr_setschedparam "pthread_attr_t * restrict attr" "const struct sched_param * restrict param" 109.Ft int 110.Fn pthread_attr_getschedparam "const pthread_attr_t * restrict attr" "struct sched_param * restrict param" 111./" .Ft int 112./" .Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy" 113./" .Ft int 114./" .Fn pthread_attr_getschedpolicy "const pthread_attr_t * restrict attr" "int * restrict policy" 115./" .Ft int 116./" .Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope" 117./" .Ft int 118./" .Fn pthread_attr_getscope "const pthread_attr_t * restrict attr" "int * restrict contentionscope" 119.Sh DESCRIPTION 120Thread attributes are used to specify parameters to 121.Fn pthread_create . 122One attribute object can be used in multiple calls to 123.Fn pthread_create , 124with or without modifications between calls. 125.Pp 126The 127.Fn pthread_attr_init 128function initializes 129.Fa attr 130with all the default thread attributes. 131.Pp 132The 133.Fn pthread_attr_destroy 134function destroys 135.Fa attr . 136.Pp 137The 138.Fn pthread_attr_set* 139functions set the attribute that corresponds to each function name. 140.Pp 141The 142.Fn pthread_attr_get* 143functions copy the value of the attribute that corresponds to each function name 144to the location pointed to by the second function parameter. 145.Pp 146The attribute parameters for the 147.Fn pthread_attr_setdetachstate 148and 149.Fn pthread_attr_getdetachstate 150are mutually exclusive and must be one of: 151.Bl -tag -width xxxxxxxx 152.It PTHREAD_CREATE_JOINABLE 153The threads must explicitely be waited for using the 154.Fn pthread_join 155function once they exit for their status to be received and their resources 156to be freed. This is the default. 157.It PTHREAD_CREATE_DETACHED 158The thread's resources will automatically be freed once the thread exits, 159and the thread will not be joined. 160.El 161.Sh RETURN VALUES 162If successful, these functions return 0. 163Otherwise, an error number is returned to indicate the error. 164.Sh ERRORS 165.Fn pthread_attr_init 166shall fail if: 167.Bl -tag -width Er 168.It Bq Er ENOMEM 169Out of memory. 170.El 171.Pp 172.Fn pthread_attr_destroy 173may fail if: 174.Bl -tag -width Er 175.It Bq Er EINVAL 176The value specified by 177.Fa attr 178is invalid. 179.El 180.Pp 181.\" .Fn pthread_attr_setstacksize 182.\" may fail if: 183.\" .Bl -tag -width Er 184.\" .It Bq Er EINVAL 185.\" .Fa stacksize 186.\" is less than 187.\" .Dv PTHREAD_STACK_MIN . 188.\" .El 189.\" .Pp 190.Fn pthread_attr_setdetachstate 191shall fail if: 192.Bl -tag -width Er 193.It Bq Er EINVAL 194The value specified by 195.Fa detachstate 196is invalid. 197.El 198.Pp 199.\" Fn pthread_attr_setinheritsched 200.\" may fail if: 201.\" .Bl -tag -width Er 202.\" .It Bq Er EINVAL 203.\" Invalid value for 204.\" .Fa attr . 205.\" .El 206.\" .Pp 207.Fn pthread_attr_setschedparam 208may fail if: 209.Bl -tag -width Er 210.It Bq Er EINVAL 211The value specified by 212.Fa attr 213is invalid. 214.It Bq Er ENOTSUP 215The value specified by 216.Fa param 217is invalid. 218.El 219.Pp 220.\" .Fn pthread_attr_setschedpolicy 221.\" may fail if: 222.\" .Bl -tag -width Er 223.\" .It Bq Er EINVAL 224.\" Invalid value for 225.\" .Fa attr . 226.\" .It Bq Er ENOTSUP 227.\" Invalid or unsupported value for 228.\" .Fa policy . 229.\" .El 230.\" .Pp 231.\" .Fn pthread_attr_setscope 232.\" may fail if: 233.\" .Bl -tag -width Er 234.\" .It Bq Er EINVAL 235.\" Invalid value for 236.\" .Fa attr . 237.\" .It Bq Er ENOTSUP 238.\" Invalid or unsupported value for 239.\" .Fa contentionscope . 240.\" .El 241.Sh SEE ALSO 242.Xr pthread_create 3 , 243.Xr pthread_join 3 244.Sh STANDARDS 245.Fn pthread_attr_init , 246.Fn pthread_attr_destroy , 247.\" .Fn pthread_attr_setstacksize , 248.\" .Fn pthread_attr_getstacksize , 249.\" .Fn pthread_attr_setstackaddr , 250.\" .Fn pthread_attr_getstackaddr , 251.Fn pthread_attr_setdetachstate , 252.Fn pthread_attr_getdetachstate , 253.\" .Fn pthread_attr_setinheritsched , 254.\" .Fn pthread_attr_getinheritsched , 255.\" .Fn pthread_attr_setschedparam , 256.Fn pthread_attr_setschedparam , 257and 258.Fn pthread_attr_getschedparam 259.\" .Fn pthread_attr_setschedpolicy , 260.\" .Fn pthread_attr_getschedpolicy , 261.\" .Fn pthread_attr_setscope , 262.\" and 263.\" .Fn pthread_attr_getscope 264conform to 265.St -p1003.1-96 . 266