Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there preemption with user-level threads

With user-level threads, can a low-priority thread be preempted to allow a high-priority thread run ?

like image 912
Sima Koding Avatar asked Sep 28 '22 09:09

Sima Koding


2 Answers

My reasoning to this question in Modern Operating Systems was:

  • A user level thread is handled by the user level process. The user process can kick its threads on or off the CPU during its allotted time slice (quantum). However, the kernel cannot see the user level thread: it just knows that a particular user process is running in its allotted time slice.

  • When a thread enters its critical section, it requires a shared resource handled by the system. Thus, a system call is made.

  • However, when a thread makes a system call, all the other threads in the parent process are blocked. This means that a sibling thread cannot preempt the blocking thread.

Therefore, although preemption can happen to a user level thread, priority inversion cannot.


Edit: After learning a bit more, I found out that preemption at user-level threads is dependent on thread model (i.e. mapping of user level threads to kernel level threads) and their implementation. Will update once further info is acquired.

like image 112
Osman Malik Avatar answered Oct 07 '22 19:10

Osman Malik


Based on my reading of the MOS by AT, I realised that the solution says so because preemption requires timer interrupts (The other way is yielding, which would never happen during critical section execution) and there are no timer interrupts at user level threads (at least it has not been discussed in the book). This doesn't mean that preemption cannot be implemented in user level threads, as discussed here.

like image 33
user3364902 Avatar answered Oct 07 '22 18:10

user3364902