1PTHREAD_CREATE(3) Linux Programmer's Manual PTHREAD_CREATE(3)
2
3
4
6 pthread_create - create a new thread
7
9 #include <pthread.h>
10
11 int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
12 void *(*start_routine) (void *), void *arg);
13
14 Compile and link with -pthread.
15
17 The pthread_create() function starts a new thread in the calling
18 process. The new thread starts execution by invoking start_routine();
19 arg is passed as the sole argument of start_routine().
20
21 The new thread terminates in one of the following ways:
22
23 * It calls pthread_exit(3), specifying an exit status value that is
24 available to another thread in the same process that calls
25 pthread_join(3).
26
27 * It returns from start_routine(). This is equivalent to calling
28 pthread_exit(3) with the value supplied in the return statement.
29
30 * It is canceled (see pthread_cancel(3)).
31
32 * Any of the threads in the process calls exit(3), or the main thread
33 performs a return from main(). This causes the termination of all
34 threads in the process.
35
36 The attr argument points to a pthread_attr_t structure whose contents
37 are used at thread creation time to determine attributes for the new
38 thread; this structure is initialized using pthread_attr_init(3) and
39 related functions. If attr is NULL, then the thread is created with
40 default attributes.
41
42 Before returning, a successful call to pthread_create() stores the ID
43 of the new thread in the buffer pointed to by thread; this identifier
44 is used to refer to the thread in subsequent calls to other pthreads
45 functions.
46
47 The new thread inherits a copy of the creating thread's signal mask
48 (pthread_sigmask(3)). The set of pending signals for the new thread is
49 empty (sigpending(2)). The new thread does not inherit the creating
50 thread's alternate signal stack (sigaltstack(2)).
51
52 The new thread inherits the calling thread's floating-point environment
53 (fenv(3)).
54
55 The initial value of the new thread's CPU-time clock is 0 (see
56 pthread_getcpuclockid(3)).
57
58 Linux-specific details
59 The new thread inherits copies of the calling thread's capability sets
60 (see capabilities(7)) and CPU affinity mask (see sched_setaffinity(2)).
61
63 On success, pthread_create() returns 0; on error, it returns an error
64 number, and the contents of *thread are undefined.
65
67 EAGAIN Insufficient resources to create another thread, or a system-
68 imposed limit on the number of threads was encountered. The
69 latter case may occur in two ways: the RLIMIT_NPROC soft
70