1.\" $OpenBSD: kthread.9,v 1.3 2000/10/12 18:06:00 aaron Exp $ 2.\" 3.\" Copyright (c) 1999 Marc Espie 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by Marc Espie 17.\" for the OpenBSD Project. 18.\" 3. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd September 1, 1999 33.Dt KTHREAD 9 34.Os 35.Sh NAME 36.Nm kthread_create , 37.Nm kthread_exit , 38.Nm kthread_create_deferred 39.Nd kernel threads. 40.Sh SYNOPSIS 41.Fd #include <sys/kthread.h> 42.Ft int 43.Fn kthread_create "void (*func)(void)" "void *arg" "struct proc **newpp" "const char *fmt" ... 44.Ft void 45.Fn kthread_exit "int ecode" 46.Ft void 47.Fn kthread_create_deferred "void (*func)(void)" "void *arg" 48.Sh DESCRIPTION 49Kernel threads are system light-weight processes: cloned from process 0 50(the swapper), sharing its memory map and limits, but with a copy of its 51file descriptor table. 52They don't receive broadcast nor group signals and they can't be swapped. 53.Pp 54Any process can call 55.Fn kthread_create 56to create a kernel thread. 57The new process starts up executing 58.Fa func 59with argument 60.Fa arg . 61If 62.Fa newpp 63is not 64.Dv NULL , 65it is filled with the address of the new process. 66.Fa fmt 67and the remaining arguments are used to name the process. 68.Pp 69A kernel thread will terminate by calling 70.Fn kthread_exit , 71with exit code 72.Fa ecode . 73.Pp 74Since the system has to be up and running for creating 75new processes, device drivers that want to create kernel threads early 76(e.g., at attach time) may use 77.Fn kthread_create_deferred 78instead. 79The system will call back the function 80.Fa func 81with argument 82.Fa arg 83when it can create threads, so it is up to 84.Fa func 85to call 86.Fn kthread_create 87at that point. 88.Sh SEE ALSO 89.Xr fork1 9 90.Sh BUGS 91There is currently no way to use 92.Va ecode 93to any sensible purpose from 94.Fn kthread_exit . 95