THREAD_FORK(9) Kernel Developer's Manual THREAD_FORK(9)

thread_forkcreate a new thread inside a process

#include <sys/types.h>
#include <sys/proc.h>

thread_fork(struct proc *p1, void *stack, void *tcb, pid_t *tidptr, register_t *retval);

() creates a new thread out of p1, which should be the current thread. This function is used to implement the __tfork(3) system call.

stack, which must not be NULL, will be used as the initial value of the new thread's stack pointer.

If tcb is not NULL, it will be used as the initial address of the new thread's TCB (thread control block).

If tidptr is not NULL, the TID of the new thread will be copied out there on success. This is guaranteed to be done before the new thread is started.

On successful completion the TID of the new thread will be stored in *retval.

Upon successful completion of the operation, thread_fork() returns 0. Otherwise, the following error values are returned:

The system limit on the total number of threads would be exceeded.
There is insufficient swap space for the new thread.
The stack argument was NULL.

__get_tcb(2), fork(2), __tfork(3), tfind(9)

The thread_fork() function appeared in OpenBSD 6.1.

February 15, 2017 OpenBSD 7.5