Types There are two types of threads in Linux systems. One is the kernel threads. The other is user threads.
KernelThreads Kernel threads run in Kernel Space and is managed by the kernel. No scheduling or whatsoever needs to be implemented in the User Space.
UserThreads User threads are managed in the user space and a run-time system is required to determine scheduling.
For pure user threads (no kernel support), creation and destruction is fast as there is no system calls and context switching involved. However, one blocking thread will block the whole process since there is no kernel support. The operating system views the process as single-threaded in this case.
For kernel level threads, its creation and destruction tends to be slower as it involves system calls (transition from user space to kernel space and so forth). Paying this price, the kernel knows about those kernel threads and can schedule another one when a thread blocks.
Many-to-one model
Many-to-one is pure user space implementation. It is fast and portable because it does not depend on the system. It is just a library. The drawback is all thread are blocked if one user thread blocks. This is because the kernel sees only one thread, the kernel thread being mapped to.
One-to-one model
One-to-one just provides wrapper methods for the kernel threads. It aims to make kernel threads easier to use and interact with. This model allows for exploiting the full parallelism of your machine at the cost of having a slower system call interface and losing some control over threads.
Many-to-Many model
many-to-many model is a mix of both. It exploits the parallelism of the kernel threads and as well avoids a number of system calls that would otherwise be called in one-to-one model. This model is constructed by capping the number of kernel threads to how many we could run in parallel. The model introduces a great deal of complexity in design although it brings best of both worlds. Java Virtual Threads Library is an example.
A thread pool is perfect for the many-to-many model as the goal of many-to-many is to reduce creation costs. A thread pool consists of a certain number of threads and a queue of tasks. Threads will be woken up and put to work as tasks come in. They will be reused when there is tasks and put to sleep when there is no work.
ProcessesAndThreads A multi-threaded process will only fork the thread that called fork(). To have some control over what happens at forking, pthread_fork comes into play.
It is unfortunate that the Linux operating system will only pick one of the threads at random when a signal is sent to a process.