Mutexlock and Prio Inversion ?

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX) ;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

-----Original Message-----
From: Joerg Kampmann [mailto:joerg.kampmann@ibk-consult.de]
Posted At: Tuesday, August 28, 2001 11:18 AM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Mutexlock and Prio Inversion ?


Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX) ;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

Yes. That’s called ‘priority inheritance protocol’ in POSIX. QNX does
not do ‘priority ceiling’ though.

  • igor

Joerg Kampmann wrote:

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX) ;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

thanks, good to hear: Otherwise there would be a “hole in philosophy”
:slight_smile:
Jörg

Igor Kovalenko schrieb:

Yes. That’s called ‘priority inheritance protocol’ in POSIX. QNX does
not do ‘priority ceiling’ though.

  • igor

Joerg Kampmann wrote:

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX) ;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

the funny thing on it is: helpfiles to not mention it “expressis verbis”

  • should be improved ! :slight_smile:
    Jörg

Rennie Allen schrieb:

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 11:18 AM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Mutexlock and Prio Inversion ?

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX) ;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

It is there. Check pthread_mutex_getprotocol. Standards are great, once
everyone knows them (until then, it simply seems that there is a lack of
documentation :slight_smile:

-----Original Message-----
From: Joerg Kampmann [mailto:joerg.kampmann@ibk-consult.de]
Posted At: Tuesday, August 28, 2001 10:04 PM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Re: Mutexlock and Prio Inversion ?


the funny thing on it is: helpfiles to not mention it “expressis verbis”

  • should be improved ! :slight_smile:
    Jörg

Rennie Allen schrieb:

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 11:18 AM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Mutexlock and Prio Inversion ?

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an
prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX)
;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the
prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

well this is quite hidden - btw. but ok, I would have wished the
explanation at a more central point :slight_smile:

In the meantime I made a little two-thread programme - with distinct
priorities per thread - and it worked - Super (nice to be seen when
the thread in question sleeps for a while and the other with higher prio
tries to mutex_lock … the prio is boosted) …

Jörg

Rennie Allen schrieb:

It is there. Check pthread_mutex_getprotocol. Standards are great, once
everyone knows them (until then, it simply seems that there is a lack of
documentation > :slight_smile:

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 10:04 PM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Re: Mutexlock and Prio Inversion ?

the funny thing on it is: helpfiles to not mention it “expressis verbis”

  • should be improved ! > :slight_smile:
    Jörg

Rennie Allen schrieb:

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 11:18 AM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Mutexlock and Prio Inversion ?

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an
prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX)
;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the
prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

however - it does not sleep faster !!! :wink: :wink: :wink: :wink:

Joerg Kampmann schrieb:

well this is quite hidden - btw. but ok, I would have wished the
explanation at a more central point > :slight_smile:

In the meantime I made a little two-thread programme - with distinct
priorities per thread - and it worked - Super (nice to be seen when
the thread in question sleeps for a while and the other with higher prio
tries to mutex_lock … the prio is boosted) …

Jörg

Rennie Allen schrieb:

It is there. Check pthread_mutex_getprotocol. Standards are great, once
everyone knows them (until then, it simply seems that there is a lack of
documentation > :slight_smile:

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 10:04 PM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Re: Mutexlock and Prio Inversion ?

the funny thing on it is: helpfiles to not mention it “expressis verbis”

  • should be improved ! > :slight_smile:
    Jörg

Rennie Allen schrieb:

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

-----Original Message-----
From: Joerg Kampmann [mailto:> joerg.kampmann@ibk-consult.de> ]
Posted At: Tuesday, August 28, 2001 11:18 AM
Posted To: os
Conversation: Mutexlock and Prio Inversion ?
Subject: Mutexlock and Prio Inversion ?

Hi,

just a little question:

if you have two threads in one process, one at prio 10 the other an
prio
11 - now assume to be blocked.

when the prio-10-thread issues first a “pthread_mutex_lock( &myMUTEX)
;”
to a critical section and then within that critical section the
prio-11-thread becomes ready and issues also a “pthread_mutex_lock(
&myMutex ) ;” and has to stop at that “myMutex”, does the
prio-10-thread
get its priority boosted up to 11 to prevent priority inversion ?

Jörg

=====================================================================
Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: > http://www.qnx.com > ====

Dr. Jörg Kampmann - IBK-Consult for Real-Time and Embedded Systems
D-31228 Peine - Tel.:+49-177-276-3140 - Fax: +49-5171-13385
http://www.ibk-consult.de
===== QNX is the better Choice for Real-Time: http://www.qnx.com ====

Rennie Allen <RAllen@csical.com> wrote:

This is a simple one. Yes. QNX Neutrino implements priority
inheritence on mutexes.

But, an important note: QNX 6 does not do (can not do) priority
inheritance on semaphores. Mainly because there is no definition
of ownership for a semaphores as there is for a mutex.

So, if you are using semaphores as a mutex (say between processes),
then you risk a priority inversion problem.

QNX 6 does allow you to use mutexes between proceses, though, if you
set the process shared flag for the mutex. (Condition variables can
also be used between processes.)

-David


QNX Training Services
dagibbs@qnx.com

In article <3B8BF5B1.74336E22@motorola.com>,
Igor Kovalenko <Igor.Kovalenko@motorola.com> writes:

Yes. That’s called ‘priority inheritance protocol’ in POSIX. QNX does
not do ‘priority ceiling’ though.

qnx 6.2.0 adds support for PTHREAD_PRIO_PROTECT. Although the
implementation seems broken to me… I’m waiting for a comment
from my bug-report (sent yesterday - so I think there is
time left for an answer :wink:

David


The point of instantiation for a template used inside another template
and not instantiated previous to an instantiation of the enclosing
template is immediately before the point of instantiation of the
enclosing template.