1.\" $OpenBSD: pthread_create.3,v 1.7 2001/06/24 18:17:30 jasoni Exp $ 2.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. 3.\" All rights reserved. 4.\" 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. All advertising materials mentioning features or use of this software 14.\" must display the following acknowledgement: 15.\" This product includes software developed by John Birrell. 16.\" 4. Neither the name of the author nor the names of any co-contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" $FreeBSD: pthread_create.3,v 1.8 1999/08/28 00:03:04 peter Exp $ 33.\" 34.Dd April 4, 1996 35.Dt PTHREAD_CREATE 3 36.Os 37.Sh NAME 38.Nm pthread_create 39.Nd create a new thread 40.Sh SYNOPSIS 41.Fd #include <pthread.h> 42.Ft int 43.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg" 44.Sh DESCRIPTION 45The 46.Fn pthread_create 47function is used to create a new thread, with attributes specified by 48.Fa attr , 49within a process. If 50.Fa attr 51is NULL, the default attributes are used. If the attributes specified by 52.Fa attr 53are modified later, the thread's attributes are not affected. Upon 54successful completion 55.Fn pthread_create 56will store the ID of the created thread in the location specified by 57.Fa thread . 58.Pp 59The thread is created executing 60.Fa start_routine 61with 62.Fa arg 63as its sole argument. If the 64.Fa start_routine 65returns, the effect is as if there was an implicit call to 66.Fn pthread_exit 67using the return value of 68.Fa start_routine 69as the exit status. Note that the thread in which 70.Fn main 71was originally invoked differs from this. When it returns from 72.Fn main , 73the effect is as if there was an implicit call to 74.Fn exit 75using the return value of 76.Fn main 77as the exit status. 78.Pp 79The signal state of the new thread is initialized as: 80.Bl -bullet -offset indent 81.It 82The signal mask is inherited from the creating thread. 83.It 84The set of signals pending for the new thread is empty. 85.El 86.Sh RETURN VALUES 87If successful, the 88.Fn pthread_create 89function will return zero. Otherwise an error number will be returned to 90indicate the error. 91.Sh ERRORS 92.Fn pthread_create 93will fail if: 94.Bl -tag -width Er 95.It Bq Er EAGAIN 96The system lacked the necessary resources to create another thread, or 97the system-imposed limit on the total number of threads in a process 98[PTHREAD_THREADS_MAX] would be exceeded. 99.It Bq Er EINVAL 100The value specified by 101.Fa attr 102is invalid. 103.El 104.Sh SEE ALSO 105.Xr fork 2 , 106.Xr pthread_attr_init 3 , 107.Xr pthread_attr_setdetachstate 3 , 108.Xr pthread_attr_setstackaddr 3 , 109.Xr pthread_attr_setstacksize 3 , 110.Xr pthread_cleanup_pop 3 , 111.Xr pthread_cleanup_push 3 , 112.Xr pthread_exit 3 , 113.Xr pthread_join 3 114.Sh STANDARDS 115.Fn pthread_create 116conforms to ISO/IEC 9945-1 ANSI/IEEE 117.Pq Dq Tn POSIX 118Std 1003.1 Second Edition 1996-07-12. 119