thrd_create — thread creation
#include <threads.h>
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
[CX] The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1-2024 defers to the ISO C standard.The thrd_create() function shall create a new thread executing func(arg). If the thrd_create() function succeeds, it shall set the object pointed to by thr to the identifier of the newly created thread. (A thread's identifier might be reused for a different thread once the original thread has exited and either been detached or joined to another thread.) The completion of the thrd_create() function shall synchronize with the beginning of the execution of the new thread.
[CX] The signal state of the new thread shall be initialized as follows:
The signal mask shall be inherited from the creating thread.
The set of signals pending for the new thread shall be empty.
The thread-local current locale shall not be inherited from the creating thread.
The floating-point environment shall be inherited from the creating thread.
[XSI] The alternate stack shall not be inherited from the creating thread.
Returning from func shall have the same behavior as invoking thrd_exit() with the value returned from func.
If thrd_create() fails, no new thread shall be created and the contents of the location referenced by thr are undefined.
[CX] The thrd_create() function shall not be affected if the calling thread executes a signal handler during the call.
The thrd_create() function shall return thrd_success on success, or thrd_nomem if no memory could be allocated for the thread requested, or thrd_error if the request could not be honored, [CX] such as if the system-imposed limit on the total number of threads in a process {PTHREAD_THREADS_MAX} would be exceeded.
See RETURN VALUE.
None.
There is no requirement on the implementation that the ID of the created thread be available before the newly created thread starts executing. The calling thread can obtain the ID of the created thread through the thr argument of the thrd_create() function, and the newly created thread can obtain its ID by a call to thrd_current().
The thrd_create() function is not affected by signal handlers for the reasons stated in XRAT B.2.3 Error Numbers .
None.
pthread_create , thrd_current , thrd_detach , thrd_exit , thrd_join
First released in Issue 8. Included for alignment with the ISO/IEC 9899:2018 standard.
return to top of page