Reputation: 41
What is the use of user level threads? I have read articles saying that user level threads are faster than kernel-level threads. User-level threads are non-preemptive and blocking of one user-level thread blocks all other user-level threads in the process.
This means that there cannot be a situation in which one user-level thread is doing IO and another user-level thread is executing. Also, as it is up to the user level thread to yield control, the user-level threads cannot be used for GUIs as well.
The question is: How are user-level threads any better than a sequential process ?
Upvotes: 4
Views: 1423
Reputation: 55907
One possible benefit: design/code organisation. By using a Thread construct we make very clear the independent pieces of processing and the places at which they need to interact.
Upvotes: 3
Reputation: 61369
You normally use user-level threads with an event loop, such that other user-level threads can continue executing while one is waiting for data: the thread scheduler polls registered file descriptors for readiness when a thread yields, and will usually prioritize the thread(s) for which input is ready. Meanwhile, the non-automatic yield has a big advantage: you often don't have to worry about concurrent access to data structures (unless the programmer is stupid and gratuitously yields in the middle of what should be an atomic operation with respect to other threads). This means less need (often no need) for synchronization and locking, which is why user-level threads often win over kernel threads: much lower overhead. And when synchronization is needed, it's often cheaper than with kernel threads.
Upvotes: 3