1fc2512cfSRobert Mustacchi.\" 2fc2512cfSRobert Mustacchi.\" This file and its contents are supplied under the terms of the 3fc2512cfSRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0. 4fc2512cfSRobert Mustacchi.\" You may only use this file in accordance with the terms of version 5fc2512cfSRobert Mustacchi.\" 1.0 of the CDDL. 6fc2512cfSRobert Mustacchi.\" 7fc2512cfSRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this 8fc2512cfSRobert Mustacchi.\" source. A copy of the CDDL is also available via the Internet at 9fc2512cfSRobert Mustacchi.\" http://www.illumos.org/license/CDDL. 10fc2512cfSRobert Mustacchi.\" 11fc2512cfSRobert Mustacchi.\" 12fc2512cfSRobert Mustacchi.\" Copyright 2016 Joyent, Inc. 13fc2512cfSRobert Mustacchi.\" 14fc2512cfSRobert Mustacchi.Dd "Jan 13, 2015" 15fc2512cfSRobert Mustacchi.Dt THRD_CREATE 3C 16fc2512cfSRobert Mustacchi.Os 17fc2512cfSRobert Mustacchi.Sh NAME 18fc2512cfSRobert Mustacchi.Nm thrd_create 19fc2512cfSRobert Mustacchi.Nd create a thread 20fc2512cfSRobert Mustacchi.Sh SYNOPSIS 21fc2512cfSRobert Mustacchi.In threads.h 22fc2512cfSRobert Mustacchi.Vt "typedef int (*thrd_start_t)(void *);" 23fc2512cfSRobert Mustacchi.Ft int 24fc2512cfSRobert Mustacchi.Fo thrd_create 25fc2512cfSRobert Mustacchi.Fa "thrd_t *thrdp" 26fc2512cfSRobert Mustacchi.Fa "thrd_start_t func" 27fc2512cfSRobert Mustacchi.Fa "void *arg" 28fc2512cfSRobert Mustacchi.Fc 29fc2512cfSRobert Mustacchi.Sh DESCRIPTION 30fc2512cfSRobert MustacchiThe 31fc2512cfSRobert Mustacchi.Fn thrd_create 32fc2512cfSRobert Mustacchifunction creates a new thread of execution inside of the current 33fc2512cfSRobert Mustacchiprocess and stores its identifier in 34fc2512cfSRobert Mustacchi.Fa thrdp . 35fc2512cfSRobert MustacchiEach thread operates concurrently within the process. 36fc2512cfSRobert Mustacchi.Pp 37fc2512cfSRobert MustacchiWhen a thread is created, it begins its execution at the function 38fc2512cfSRobert Mustacchi.Fa func 39fc2512cfSRobert Mustacchiwith the argument 40fc2512cfSRobert Mustacchi.Fa arg . 41fc2512cfSRobert MustacchiA created thread has access to all global data within a process; 4272d3dbb9SYuri Pankovhowever, it has its own private stack. 4372d3dbb9SYuri PankovCurrently 32-bit processes have a default stack of 1 megabyte, while 64-bit 4472d3dbb9SYuri Pankovsystems have a default stack size of 2 megabytes. 4572d3dbb9SYuri PankovIn addition, newly created threads inherit the signal mask of the thread which 4672d3dbb9SYuri Pankovcreated them; however, they do not inherit any pending signals. 47fc2512cfSRobert Mustacchi.Pp 48fc2512cfSRobert MustacchiOnce created, a thread will continue to execute until either, it returns 49fc2512cfSRobert Mustacchifrom its initial function, the thread explicitly calls 50fc2512cfSRobert Mustacchi.Xr thrd_exit 3C , 51fc2512cfSRobert Mustacchior the process itself terminates, such as with a call to 52fc2512cfSRobert Mustacchi.Xr exit 2 . 53fc2512cfSRobert MustacchiWhen the initial function returns, it behaves as though a call to 5472d3dbb9SYuri Pankov.Xr thrd_exit 3C 55fc2512cfSRobert Mustacchiwas made, and, if the thread has not been detached with a call to 5672d3dbb9SYuri Pankov.Xr thrd_detach 3C , 57fc2512cfSRobert Mustacchithe exit status remains available and the corresponding thread ID will 58fc2512cfSRobert Mustacchinot be reused until a process calls 59fc2512cfSRobert Mustacchi.Xr thrd_join 3C . 60fc2512cfSRobert MustacchiThis is similar to how a parent must call 61b31ca922SChris Fraire.Xr wait 3C , 62fc2512cfSRobert Mustacchito clean up a child process that has terminated. 63fc2512cfSRobert Mustacchi.Pp 64fc2512cfSRobert MustacchiFor a richer interface interface with more control over aspects of the 65fc2512cfSRobert Mustacchinewly created thread, such as stack size, stack placement, and the like, 66fc2512cfSRobert Mustacchisee 67fc2512cfSRobert Mustacchi.Xr thr_create 3C 68fc2512cfSRobert Mustacchiand 69fc2512cfSRobert Mustacchi.Xr pthread_create 3C . 70fc2512cfSRobert Mustacchi.Sh RETURN VALUES 71fc2512cfSRobert MustacchiUpon successful completion, the 72fc2512cfSRobert Mustacchi.Fn thrd_create 73fc2512cfSRobert Mustacchifunction returns 74fc2512cfSRobert Mustacchi.Sy thrd_success . 75fc2512cfSRobert MustacchiIf insufficient memory was available, then 76fc2512cfSRobert Mustacchi.Sy thrd_nomem 7772d3dbb9SYuri Pankovis returned. 7872d3dbb9SYuri PankovOtherwise, 79fc2512cfSRobert Mustacchi.Sy thrd_error 80fc2512cfSRobert Mustacchiis returned, indicating that a non-memory related error. 81fc2512cfSRobert Mustacchi.Sh INTERFACE STABILITY 82fc2512cfSRobert Mustacchi.Sy Standard 83fc2512cfSRobert Mustacchi.Sh MT-LEVEL 84fc2512cfSRobert Mustacchi.Sy MT-Safe 85fc2512cfSRobert Mustacchi.Sh SEE ALSO 86fc2512cfSRobert Mustacchi.Xr pthread_create 3C , 87fc2512cfSRobert Mustacchi.Xr thr_create 3C , 88fc2512cfSRobert Mustacchi.Xr thrd_detach 3C , 89fc2512cfSRobert Mustacchi.Xr thrd_join 3C , 90*bbf21555SRichard Lowe.Xr attributes 7 , 91*bbf21555SRichard Lowe.Xr threads 7 92