1*d13ac072Suwe.\" $NetBSD: pthread_create.3,v 1.9 2023/04/29 21:37:07 uwe Exp $ 255818196Snathanw.\" 355818196Snathanw.\" Copyright (c) 2002 The NetBSD Foundation, Inc. 455818196Snathanw.\" All rights reserved. 555818196Snathanw.\" Redistribution and use in source and binary forms, with or without 655818196Snathanw.\" modification, are permitted provided that the following conditions 755818196Snathanw.\" are met: 855818196Snathanw.\" 1. Redistributions of source code must retain the above copyright 955818196Snathanw.\" notice, this list of conditions and the following disclaimer. 1055818196Snathanw.\" 2. Redistributions in binary form must reproduce the above copyright 1155818196Snathanw.\" notice, this list of conditions and the following disclaimer in the 1255818196Snathanw.\" documentation and/or other materials provided with the distribution. 1355818196Snathanw.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1455818196Snathanw.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1555818196Snathanw.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1655818196Snathanw.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1755818196Snathanw.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1855818196Snathanw.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1955818196Snathanw.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2055818196Snathanw.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2155818196Snathanw.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2255818196Snathanw.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2355818196Snathanw.\" POSSIBILITY OF SUCH DAMAGE. 2455818196Snathanw.\" 2555818196Snathanw.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. 2655818196Snathanw.\" All rights reserved. 2755818196Snathanw.\" 2855818196Snathanw.\" Redistribution and use in source and binary forms, with or without 2955818196Snathanw.\" modification, are permitted provided that the following conditions 3055818196Snathanw.\" are met: 3155818196Snathanw.\" 1. Redistributions of source code must retain the above copyright 3255818196Snathanw.\" notice, this list of conditions and the following disclaimer. 3355818196Snathanw.\" 2. Redistributions in binary form must reproduce the above copyright 3455818196Snathanw.\" notice, this list of conditions and the following disclaimer in the 3555818196Snathanw.\" documentation and/or other materials provided with the distribution. 3655818196Snathanw.\" 3. All advertising materials mentioning features or use of this software 3755818196Snathanw.\" must display the following acknowledgement: 3855818196Snathanw.\" This product includes software developed by John Birrell. 3955818196Snathanw.\" 4. Neither the name of the author nor the names of any co-contributors 4055818196Snathanw.\" may be used to endorse or promote products derived from this software 4155818196Snathanw.\" without specific prior written permission. 4255818196Snathanw.\" 4355818196Snathanw.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 4455818196Snathanw.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4555818196Snathanw.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4655818196Snathanw.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 4755818196Snathanw.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4855818196Snathanw.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4955818196Snathanw.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5055818196Snathanw.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5155818196Snathanw.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5255818196Snathanw.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5355818196Snathanw.\" SUCH DAMAGE. 5455818196Snathanw.\" 5555818196Snathanw.\" $FreeBSD: src/lib/libpthread/man/pthread_create.3,v 1.16 2002/09/16 19:29:28 mini Exp $ 5655818196Snathanw.\" 579c4ae7f5Sjruoho.Dd July 9, 2010 5855818196Snathanw.Dt PTHREAD_CREATE 3 5955818196Snathanw.Os 6055818196Snathanw.Sh NAME 6155818196Snathanw.Nm pthread_create 6255818196Snathanw.Nd create a new thread 6355818196Snathanw.Sh LIBRARY 6455818196Snathanw.Lb libpthread 6555818196Snathanw.Sh SYNOPSIS 6655818196Snathanw.In pthread.h 67*d13ac072Suwe. 6855818196Snathanw.Ft int 69*d13ac072Suwe.Fo pthread_create 70*d13ac072Suwe.Fa "pthread_t * restrict thread" 71*d13ac072Suwe.Fa "const pthread_attr_t * restrict attr" 72*d13ac072Suwe.Fa "void *(*start_routine)(void *)" 73*d13ac072Suwe.Fa "void * restrict arg" 74*d13ac072Suwe.Fc 75*d13ac072Suwe. 7655818196Snathanw.Sh DESCRIPTION 7755818196SnathanwThe 7855818196Snathanw.Fn pthread_create 7955818196Snathanwfunction is used to create a new thread, with attributes specified by 8055818196Snathanw.Fa attr , 8155818196Snathanwwithin a process. 8255818196SnathanwIf 8355818196Snathanw.Fa attr 8455818196Snathanwis 8555818196Snathanw.Dv NULL , 8655818196Snathanwthe default attributes are used. 874035b6eeSdholland.Pp 884035b6eeSdhollandThe attributes specified via 8955818196Snathanw.Fa attr 904035b6eeSdhollandare copied into the new thread. 914035b6eeSdhollandAny subsequent modifications to the attributes object 924035b6eeSdholland.Fa attr 934035b6eeSdhollandpoints to will have no effect upon already-created threads. 944035b6eeSdhollandIt is thus also safe to pass the same 954035b6eeSdholland.Fa attr 964035b6eeSdhollandto multiple calls to 974035b6eeSdholland.Fn pthread_create . 984035b6eeSdholland.Pp 9955818196SnathanwUpon 10055818196Snathanwsuccessful completion 10155818196Snathanw.Fn pthread_create 10255818196Snathanwwill store the ID of the created thread in the location specified by 10355818196Snathanw.Fa thread . 10455818196SnathanwThe thread is created executing 10555818196Snathanw.Fa start_routine 10655818196Snathanwwith 10755818196Snathanw.Fa arg 10855818196Snathanwas its sole argument. 1094035b6eeSdholland.Pp 11055818196SnathanwIf the 11155818196Snathanw.Fa start_routine 11255818196Snathanwreturns, the effect is as if there was an implicit call to 113*d13ac072Suwe.Xr pthread_exit 3 11455818196Snathanwusing the return value of 11555818196Snathanw.Fa start_routine 11655818196Snathanwas the exit status. 11755818196SnathanwNote that the thread in which 11855818196Snathanw.Fn main 11955818196Snathanwwas originally invoked differs from this. 12055818196SnathanwWhen it returns from 12155818196Snathanw.Fn main , 12255818196Snathanwthe effect is as if there was an implicit call to 123*d13ac072Suwe.Xr exit 3 12455818196Snathanwusing the return value of 12555818196Snathanw.Fn main 12655818196Snathanwas the exit status. 12755818196Snathanw.Pp 12855818196SnathanwThe signal state of the new thread is initialized as: 12955818196Snathanw.Bl -bullet -offset indent 13055818196Snathanw.It 13155818196SnathanwThe signal mask is inherited from the creating thread. 13255818196Snathanw.It 13355818196SnathanwThe set of signals pending for the new thread is empty. 13455818196Snathanw.El 13555818196Snathanw.Sh RETURN VALUES 13655818196SnathanwIf successful, the 13755818196Snathanw.Fn pthread_create 13855818196Snathanwfunction will return zero. 13955818196SnathanwOtherwise an error number will be returned to 14055818196Snathanwindicate the error. 14155818196Snathanw.Sh ERRORS 14255818196Snathanw.Fn pthread_create 14355818196Snathanwshall fail if: 14455818196Snathanw.Bl -tag -width Er 14555818196Snathanw.It Bq Er EAGAIN 14655818196SnathanwThe system lacks the necessary resources to create another thread, or 14755818196Snathanwthe system-imposed limit on the total number of threads in a process 1489edf0547Swiz.Dv PTHREAD_THREADS_MAX 1499edf0547Swizwould be exceeded. 15055818196Snathanw.It Bq Er EINVAL 15155818196SnathanwThe value specified by 15255818196Snathanw.Fa attr 15355818196Snathanwis invalid. 15455818196Snathanw.El 15555818196Snathanw.Sh SEE ALSO 15655818196Snathanw.Xr fork 2 , 1574035b6eeSdholland.Xr pthread_attr 3 , 15855818196Snathanw.Xr pthread_cleanup_pop 3 , 15955818196Snathanw.Xr pthread_cleanup_push 3 , 16055818196Snathanw.Xr pthread_exit 3 , 16155818196Snathanw.Xr pthread_join 3 16255818196Snathanw.Sh STANDARDS 1639c4ae7f5SjruohoThe function conforms to 1649c4ae7f5Sjruoho.St -p1003.1-2001 . 165