views:

110

answers:

3

How does one create a Kernel Thread using Posix library?

+2  A: 

POSIX doesn't specify whether threads are implemented in userspace or the kernel - that's up to the implementation.

So the answer is: pthread_create, as long as your implementation does use kernel threads. If you're using glibc on Linux, you'll be fine.

caf
Except that glibc is generally not linked into the kernel, and even if it was, pthreads wouldn't be kernel threads - they would just be pthreads running in kernel space.
Dipstick
"Kernel threads" usually means threads that are *visible to* the kernel, not threads of control *within* the kernel. See, for example, this Wikipedia article: http://en.wikipedia.org/wiki/Thread_%28computer_science%29 (this is the common use of the terminology).
caf
A: 

You can't.

pthreads are for use in userland processes not the kernel. kernel threads are far more "lightweight" than pthreads (e.g. have very small fixed length stacks). kthread_create is used to create kernel threads in linux.

Dipstick
"Kernel Threads" has a commonly-used meaning of "Threads (for userspace process) implemented as seperate kernel-level threads", as opposed to threads that are implemented entirely in userspace.
caf
+1  A: 

Just to give you little background, Other OS'es had processes and threads in kernel like solaris,windows etc. But linux didn't implement threads in linux kernel, instead they provided option to pass flags which allow processes to share the VM, Open files etc..

Hope this helps.

Algorist