views:

84

answers:

2

Is writing a code for implementing the thread library a part of kernel code ? Is the function implementation of pthread_create() et al a part of kernel ?

+3  A: 

Threads are sometimes implemented purely in user space (then also called "green threads"), but typically in kernel space. The wikipedia article explains it nicely.

Martin v. Löwis
+5  A: 

In Linux, pthread_create() et al. is implemented as part of the glibc project. It uses the (non-portable, Linux-specific) syscall clone(). (Linux's fork() is also implemented in terms of clone()). Some of the BSDs also have similar syscall called rfork().

My understanding is that clone() or rfork() will both create a new process, but you can specify a flag that says, "use copy-on-write semantics to give this a different address space". So, if you want fork(), you specify that flag, but if you want to create a thread, you don't, and you end up with a shared address space.

(edited to provide more detail)

asveikau