Thread Creation, Execution, and Termination

A process is always created with one thread, called the initial thread. The initial thread provides compatibility with previous single-threaded processes. The initial thread's stack is the process stack.

See Kernel Process Creation, Execution, and Termination to get more information about kernel process creation.

Other threads can be created, using a two-step procedure. The thread_create kernel service allocates and initializes a new thread, and sets its state to idle. The kthread_start kernel service then starts the thread, using the specified entry point routine.

A thread is terminated when it executes a return from its entry point, or when it calls the thread_terminate kernel service. Its resources are automatically freed. If it is the last thread in the process, the process ends.