1PTHREAD_CREATE(3)          Linux Programmer's Manual         PTHREAD_CREATE(3)
2
3
4

NAME

6       pthread_create - create a new thread
7

SYNOPSIS

9       #include <pthread.h>
10
11       int pthread_create(pthread_t *restrict thread,
12                          const pthread_attr_t *restrict attr,
13                          void *(*start_routine)(void *),
14                          void *restrict arg);
15
16       Compile and link with -pthread.
17

DESCRIPTION

19       The  pthread_create()  function  starts  a  new  thread  in the calling
20       process.  The new thread starts execution by invoking  start_routine();
21       arg is passed as the sole argument of start_routine().
22
23       The new thread terminates in one of the following ways:
24
25       * It  calls  pthread_exit(3),  specifying  an exit status value that is
26         available  to  another  thread  in  the  same  process   that   calls
27         pthread_join(3).
28
29       * It  returns  from  start_routine().   This  is  equivalent to calling
30         pthread_exit(3) with the value supplied in the return statement.
31
32       * It is canceled (see pthread_cancel(3)).
33
34       * Any of the threads in the process calls exit(3), or the  main  thread
35         performs  a  return  from main().  This causes the termination of all
36         threads in the process.
37
38       The attr argument points to a pthread_attr_t structure  whose  contents
39       are  used  at  thread creation time to determine attributes for the new
40       thread; this structure is initialized  using  pthread_attr_init(3)  and
41       related  functions.   If  attr is NULL, then the thread is created with
42       default attributes.
43
44       Before returning, a successful call to pthread_create() stores  the  ID
45       of  the  new thread in the buffer pointed to by thread; this identifier
46       is used to refer to the thread in subsequent calls  to  other  pthreads
47       functions.
48
49       The  new  thread  inherits  a copy of the creating thread's signal mask
50       (pthread_sigmask(3)).  The set of pending signals for the new thread is
51       empty  (sigpending(2)).   The  new thread does not inherit the creating
52       thread's alternate signal stack (sigaltstack(2)).
53
54       The new thread inherits the calling thread's floating-point environment
55       (fenv(3)).
56
57       The  initial  value  of  the  new  thread's  CPU-time  clock  is 0 (see
58       pthread_getcpuclockid(3)).
59
60   Linux-specific details
61       The new thread inherits copies of the calling thread's capability  sets
62       (see capabilities(7)) and CPU affinity mask (see sched_setaffinity(2)).
63

RETURN VALUE

65       On  success,  pthread_create() returns 0; on error, it returns an error
66       number, and the contents of *thread are undefined.
67

ERRORS

69       EAGAIN Insufficient resources to create another thread.
70
71       EAGAIN A system-imposed limit on the number of threads was encountered.
72              There  are  a  number of limits