Gervais Mulongoy
|
Re: Mutex priority inheritance related question
|
Gervais Mulongoy
04/22/2021 3:00 PM
post121392
|
Re: Mutex priority inheritance related question
My vote is B.
________________________________
From: Steven Dufresne <community-noreply@qnx.com>
Sent: April 22, 2021 2:57:41 PM
To: ostech-core_os
Subject: Mutex priority inheritance related question
Here's a question that came up while teaching priority inheritance w.r.t. mutex locking in class today...
Let's say thread A is RUNNING and B is READY both at priority 21 on a single core system. We also have C at priority 10
with a mutex locked. Thread A calls pthread_mutex_lock() to lock that mutex. A of course MUTEX blocks and C's priority
is bumped up to 21. The question is who runs when C unlocks the mutex, A or B? B is next in the list but will A be moved
to the head of the list and run instead?
Thanks,
Steve
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post121391
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
|
|
|
Thomas Haupt
|
Re: Mutex priority inheritance related question
|
Thomas Haupt
04/23/2021 5:46 AM
post121393
|
Re: Mutex priority inheritance related question
When the mutex is unlocked, A goes to the end of the READY queue and B becomes running again right away.
|
|
|
Elad Lahav
|
Re: Mutex priority inheritance related question
|
Elad Lahav
04/23/2021 7:06 AM
post121396
|
Re: Mutex priority inheritance related question
Generally speaking a thread that blocks goes to the end of the ready queue when it unblocks (there are a few exceptions)
. Whether it runs after all threads ahead of it in the queue at the same priority level may depend on other factors
(such as runmasks and APS partitions). Moreover, you can have thread B put into execution on CPU 1, followed by thread A
put into execution on CPU 2, and almost immediately a higher priority thread preempting B on CPU 1, before B could
execute a single instruction.
Reasoning about order of execution is really hard, especially on SMP systems.
--Elad
|
|
|