How to implement a thread library?

Is the code for implementing the thread library part of the kernel code? Is the implementation of pthread_create (), etc. a part of the kernel?

+4
source share
2 answers

On Linux, pthread_create() et al. implemented as part of the glibc project. It uses (not portable, specific for Linux) syscall clone() . (Linux fork() also implemented in terms of clone() ). Some of the BSDs also have a similar syscall called rfork() .

I understand that clone() or rfork() will create a new process, but you can specify a flag that says: β€œUse copy-to-write semantics to give this a different address space.” So, if you want fork() , you specify this flag, but if you want to create a stream, you will not do this, and you will get a common address space.

(edited for more details)

+5
source

Themes are sometimes implemented exclusively in user space (then also called "green threads"), but usually in kernel space. Wikipedia article perfectly explains this.

+3
source

All Articles