# What is the purpose of M:N (Hybrid) threading?

In other words, what advantages does Hybrid threading have over 1:1 (kernel only) and N:1 (user only) threading?

This is a follow-up to What is the difference between user-level threads and kernel-level threads?

• Please explain the concepts shortly or link to appropriate references. – Raphael Apr 6 '12 at 11:03
• Um, that you get the benefits of both? (@Raphael Done.) – Gilles Apr 6 '12 at 11:31
• Also, the Wikipedia article seems to list some (dis)advantage. What specificly are you looking for? – Raphael Apr 6 '12 at 11:42

## 1 Answer

I think hybrid threading is very similar to a thread pool.

In thread pool, you are using $N$ kernel threads to execute $M$ “tasks”, where $M$ can be much higher than $N$. The advantage over using one thread for each task (kernel only threading) is that you consume less resources, like memory (both virtual and physical) and kernel objects (at least in the specific case of Windows threads, but I imagine other OSes are similar in this regard). You also get less context switches, which increases performance (in the ideal case, where you have as many running threads as you have processors, you may have almost no context switches).

The advantage over user only threading is that you can take advantage of multiple CPUs or multiple CPU cores. And if one task blocks, you can create another kernel thread to use the available CPU more efficiently.

So, you get the advantages of both approaches, at the expense of some additional user-mode scheduling.

A disadvantage over kernel only scheduling is possibly bigger latency: if all the threads in the pool are busy and you add new short task, you may wait a long time before it starts executing.