Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jan 2004 17:44:22 -0500 (EST)
From:      Robert Watson <rwatson@freebsd.org>
To:        Renaud Molla Wanadoo <renaud.molla@wanadoo.fr>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: kernel threads
Message-ID:  <Pine.NEB.3.96L.1040127173948.47712D-100000@fledge.watson.org>
In-Reply-To: <4016B48C.7030001@wanadoo.fr>

next in thread | previous in thread | raw e-mail | index | archive | help

On Tue, 27 Jan 2004, Renaud Molla Wanadoo wrote:

> I'm trying to use the kthread library under 5.2-RELEASE but can't
> compile my program (which actually only tries to create a thread). 
> 
> I've read that there is now KSE to create kernel threads, but i am
> wondering if it could be used within the kernel code. 

I'm left a little unclear by your message what it is you're trying to do. 
In traditional parlance, a "kernel thread" is a thread executing kernel
code in the kernel.  These are created using the kthread(9) API, which is
available both to kernel modules and code compiled directly into the
kernel.  You can see examples of kthread use (both compiled in and in
modules) by grepping in the src/sys/kern and src/sys/dev/* trees.  The
only real caveat here that I know if is that you need to grab the Giant
lock if your thread will use it, since kthreads don't start holding Giant,
and that if you call kthread_exit(), you will need to grab Giant before
that. 

A use of "kernel thread" popularized by linux is the idea of userspace
threads that are backed by a kernel schedulable thread, as opposed to
multiple userspace threads being mapped into a single thread making up a
single process. In FreeBSD 5.x, the "libc_r" library provides multiple
user threads multiplexed onto a single kernel-visible thread/process.
"libkse" and "libthr" provide M:N and 1:1 models.  By linking your
application against libkse or libthr and using the pthreads API, you will
automatically get parallelism and latency improvements over libc_r.

Hope this helps. 

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert@fledge.watson.org      Senior Research Scientist, McAfee Research



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1040127173948.47712D-100000>