KTHREAD(9)

NAME
kthread_create1, kthread_exit, kthread_create - kernel threads

SYNOPSIS
#include <sys/kthread.h>
void
kthread_create(void (*func)(void *), void *arg);
void
kthread_exit(int ecode);
int
kthread_create1(void (*func)(void *), void *arg, struct proc **newpp, const char *fmt, ...);

DESCRIPTION
Kernel threads are light-weight processes which execute entirely within the kernel. Any process can request the creation of a new kernel thread. Kernel threads are not swapped out during memory congestion. The VM space and limits are shared with proc0 (usually swapper). A kernel thread must call kthread_exit() to end execution.

FUNCTIONS

kthread_create1(void (*func)(void *), void *arg, struct proc **newpp, const char *fmt, ...)
    Fork a kernel thread. newpp is a pointer the new proc structure for the kernel thread. The function func is called with arguments arg to commence execution. fmt is a string containing format information used to display the kernel thread name. The function func must not return. If the kernel thread runs to completion, it must call kthread_exit() to properly terminate itself.

kthread_create(void (*func)(void *), void *arg)
    Register function func to defer creation of the kernel thread. Deferral of kernel thread creation is required during system startup when kernel thread resources are not available.

kthread_exit(int ecode)
    Exit from a kernel thread.

RETURN VALUES
Upon successful completion, kthread_create1() returns 0. Otherwise, the following error values are returned:

[EAGAIN]
    The limit on the total number of system processes would be exceeded.

[EAGAIN]
    The limit RLIMIT_NPROC on the total number of processes under execution by this user id would be exceeded.

CODE REFERENCES
This section describes places within the NetBSD source tree where actual code implementing or using the kthread framework can be found. All pathnames are relative to /usr/src.

The kthread framework itself is implemented within the file sys/kern/kern_kthread.c. Data structures and function prototypes for the framework are located in sys/sys/kthread.h.

SEE ALSO
driver(9), fork1(9)

HISTORY
The kthread framework appeared in NetBSD 1.4.