Name some advantages and disadvantages of user-level threads
Answer:
Advantages of user-level threads include:
- Theoretically greater performance, as the OS does not need to perform expensive context switches every time a thread changes.
- More configurable, as you are not tied to the kernel to decide a scheduling algorithm, nor do you require kernel support for multiple threads.
Disadvantages of user-level threads include:
- Realistically worse performance, because many threads require a context switch regardless (say a
syscall is called, such as on an I/O event). This will force a switch into kernel mode and BLOCK every single other user-level thread in that process from running, because the kernel treats the entire userspace of threads as a single process.
- User level threads are generally co-operative rather than pre-emptive, so must manually yield() to return control back to the dispatcher – a thread that does not do this may monopolise the CPU.
- I/O must be non-blocking – this requires extra checking just in case there is an action that should block.
- We cannot take advantage of multiprocessors, since the kernel sees one process with one thread.