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 ?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With