NAME

thrd_create — thread creation

SYNOPSIS

#include <threads.h>

int thrd_create(thrd_t *
thr, thrd_start_t func, void *arg);

DESCRIPTION

[CX] [Option Start] 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. [Option End]

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] [Option Start] The signal state of the new thread shall be initialized as follows:

The thread-local current locale shall not be inherited from the creating thread.

The floating-point environment shall be inherited from the creating thread. [Option End]

[XSI] [Option Start] The alternate stack shall not be inherited from the creating thread. [Option End]

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] [Option Start] The thrd_create() function shall not be affected if the calling thread executes a signal handler during the call. [Option End]

RETURN VALUE

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] [Option Start]  such as if the system-imposed limit on the total number of threads in a process {PTHREAD_THREADS_MAX} would be exceeded. [Option End]

ERRORS

See RETURN VALUE.


The following sections are informative.

EXAMPLES

None.

APPLICATION USAGE

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().

RATIONALE

The thrd_create() function is not affected by signal handlers for the reasons stated in XRAT B.2.3 Error Numbers .

FUTURE DIRECTIONS

None.

SEE ALSO

pthread_create , thrd_current , thrd_detach , thrd_exit , thrd_join

XBD 4.15.2 Memory Synchronization , <threads.h>

CHANGE HISTORY

First released in Issue 8. Included for alignment with the ISO/IEC 9899:2018 standard.

End of informative text.