.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages@gmail.com>
.\"
-.\" %%%LICENSE_START(VERBATIM)
-.\" Permission is granted to make and distribute verbatim copies of this
-.\" manual provided the copyright notice and this permission notice are
-.\" preserved on all copies.
+.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
-.\" Permission is granted to copy and distribute modified versions of this
-.\" manual under the conditions for verbatim copying, provided that the
-.\" entire resulting derived work is distributed under the terms of a
-.\" permission notice identical to this one.
-.\"
-.\" Since the Linux kernel and libraries are constantly changing, this
-.\" manual page may be incorrect or out-of-date. The author(s) assume no
-.\" responsibility for errors or omissions, or for damages resulting from
-.\" the use of the information contained herein. The author(s) may not
-.\" have taken the same level of care in the production of this manual,
-.\" which is licensed free of charge, as they might when working
-.\" professionally.
-.\"
-.\" Formatted or processed versions of this manual, if unaccompanied by
-.\" the source, must acknowledge the copyright and authors of this work.
-.\" %%%LICENSE_END
-.\"
-.TH PTHREAD_CREATE 3 2020-11-01 "Linux" "Linux Programmer's Manual"
+.TH PTHREAD_CREATE 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
.SH NAME
pthread_create \- create a new thread
+.SH LIBRARY
+POSIX threads library
+.RI ( libpthread ", " \-lpthread )
.SH SYNOPSIS
.nf
.B #include <pthread.h>
.PP
-.BI "int pthread_create(pthread_t *" thread ", const pthread_attr_t *" attr ,
-.BI " void *(*" start_routine ")(void *), void *" arg );
+.BI "int pthread_create(pthread_t *restrict " thread ,
+.BI " const pthread_attr_t *restrict " attr ,
+.BI " void *(*" start_routine ")(void *),"
+.BI " void *restrict " arg );
.fi
-.PP
-Compile and link with \fI\-pthread\fP.
.SH DESCRIPTION
The
.BR pthread_create ()
function starts a new thread in the calling process.
The new thread starts execution by invoking
.IR start_routine ();
-.IR arg
+.I arg
is passed as the sole argument of
.IR start_routine ().
.PP
.BR pthread_create ()
returns 0;
on error, it returns an error number, and the contents of
-.IR *thread
+.I *thread
are undefined.
.SH ERRORS
.TP
.\" NOTE! The following should match the description in fork(2)
A system-imposed limit on the number of threads was encountered.
There are a number of limits that may trigger this error: the
-.BR RLIMIT_NPROC
+.B RLIMIT_NPROC
soft resource limit (set via
.BR setrlimit (2)),
which limits the number of processes and threads for a real user ID,
was reached;
the kernel's system-wide limit on the number of processes and threads,
-.IR /proc/sys/kernel/threads-max ,
+.IR /proc/sys/kernel/threads\-max ,
was reached (see
.BR proc (5));
or the maximum number of PIDs,
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
+.ad l
+.nh
.TS
allbox;
-lb lb lb
+lbx lb lb
l l l.
Interface Attribute Value
T{
.BR pthread_create ()
T} Thread safety MT-Safe
.TE
+.hy
+.ad
.sp 1
-.SH CONFORMING TO
+.SH STANDARDS
POSIX.1-2001, POSIX.1-2008.
.SH NOTES
See
.BR pthread_self (3)
for further information on the thread ID returned in
-.IR *thread
+.I *thread
by
.BR pthread_create ().
Unless real-time scheduling policies are being employed,
.BR pthread_attr_setdetachstate (3)).
.PP
Under the NPTL threading implementation, if the
-.BR RLIMIT_STACK
+.B RLIMIT_STACK
soft resource limit
-.IR "at the time the program started"
+.I at the time the program started
has any value other than "unlimited",
then it determines the default stack size of new threads.
Using
argument used to create a thread,
in order to obtain a stack size other than the default.
If the
-.BR RLIMIT_STACK
+.B RLIMIT_STACK
resource limit is set to "unlimited",
a per-architecture value is used for the stack size.
Here is the value for a few architectures:
char *uargv;
printf("Thread %d: top of stack near %p; argv_string=%s\en",
- tinfo\->thread_num, &p, tinfo\->argv_string);
+ tinfo\->thread_num, (void *) &tinfo, tinfo\->argv_string);
uargv = strdup(tinfo\->argv_string);
if (uargv == NULL)
{
int s, opt, num_threads;
pthread_attr_t attr;
- size_t stack_size;
+ ssize_t stack_size;
void *res;
/* The "\-s" option specifies a stack size for our threads. */
break;
default:
- fprintf(stderr, "Usage: %s [\-s stack-size] arg...\en",
+ fprintf(stderr, "Usage: %s [\-s stack\-size] arg...\en",
argv[0]);
exit(EXIT_FAILURE);
}