thread_create Kernel Service

Purpose

Creates a new kernel thread in the calling process.

Syntax

#include <sys/thread.h>
tid_t thread_create ()

Description

The thread_create kernel service creates a new kernel-only thread in the calling kernel process. The thread's ID is returned; it is unique system wide.

The new thread does not begin running immediately; its state is set to TSIDL. The execution will start after a call to the kthread_start kernel service. If the process is exited prior to the thread being made runnable, the thread's resources are released immediately. The thread's signal mask is inherited from the calling thread; the set of pending signals is cleared. Signals sent to the thread are marked pending while the thread is in the TSIDL state.

If the calling thread is bound to a specific processor, the new thread will also be bound to the processor.

Execution Environment

The thread_create kernel service can be called from the process environment only. This service cannot be called directly from a kernel extension.

Return Values

Upon successful completion, the new thread's ID is returned. Otherwise, -1 is returned, and the error code can be checked by calling the getuerror kernel service.

Error Codes

Item Description
EAGAIN The total number of kernel threads executing system wide or the maximum number of kernel threads per process would be exceeded.
ENOMEM There is not sufficient memory to create the kernel thread.
ENOTSUP The thread_create service was called directly from a kernel extension.