xref: /titanic_52/usr/src/man/man3c/thrd_create.3c (revision 4a5d661a82b942b6538acd26209d959ce98b593a)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2016 Joyent, Inc.
13.\"
14.Dd "Jan 13, 2015"
15.Dt THRD_CREATE 3C
16.Os
17.Sh NAME
18.Nm thrd_create
19.Nd create a thread
20.Sh SYNOPSIS
21.In threads.h
22.Vt "typedef int (*thrd_start_t)(void *);"
23.Ft int
24.Fo thrd_create
25.Fa "thrd_t *thrdp"
26.Fa "thrd_start_t func"
27.Fa "void *arg"
28.Fc
29.Sh DESCRIPTION
30The
31.Fn thrd_create
32function creates a new thread of execution inside of the current
33process and stores its identifier in
34.Fa thrdp .
35Each thread operates concurrently within the process.
36.Pp
37When a thread is created, it begins its execution at the function
38.Fa func
39with the argument
40.Fa arg .
41A created thread has access to all global data within a process;
42however, it has its own private stack. Currently 32-bit processes have a
43default stack of 1 megabyte, while 64-bit systems have a default stack
44size of 2 megabytes. In addition, newly created threads inherit the
45signal mask of the thread which created them; however, they do not
46inherit any pending signals.
47.Pp
48Once created, a thread will continue to execute until either, it returns
49from its initial function, the thread explicitly calls
50.Xr thrd_exit 3C ,
51or the process itself terminates, such as with a call to
52.Xr exit 2 .
53When the initial function returns, it behaves as though a call to
54.Xr thrd_exit
55was made, and, if the thread has not been detached with a call to
56.Xr thrd_detach,
57the exit status remains available and the corresponding thread ID will
58not be reused until a process calls
59.Xr thrd_join 3C .
60This is similar to how a parent must call
61.Xr wait 2 ,
62to clean up a child process that has terminated.
63.Pp
64For a richer interface interface with more control over aspects of the
65newly created thread, such as stack size, stack placement, and the like,
66see
67.Xr thr_create 3C
68and
69.Xr pthread_create 3C .
70.Sh RETURN VALUES
71Upon successful completion, the
72.Fn thrd_create
73function returns
74.Sy thrd_success .
75If insufficient memory was available, then
76.Sy thrd_nomem
77is returned. Otherwise,
78.Sy thrd_error
79is returned, indicating that a non-memory related error.
80.Sh INTERFACE STABILITY
81.Sy Standard
82.Sh MT-LEVEL
83.Sy MT-Safe
84.Sh SEE ALSO
85.Xr pthread_create 3C ,
86.Xr thr_create 3C ,
87.Xr thrd_detach 3C ,
88.Xr thrd_join 3C ,
89.Xr attributes 5 ,
90.Xr threads 5
91