Article View: comp.lang.c
Article #2086Re: Why ordered mutexed don't work ...
From: David Brown
Date: Wed, 02 Dec 2026 13:49
Date: Wed, 02 Dec 2026 13:49
50 lines
3818 bytes
3818 bytes
On 02/12/2026 14:09, Bonita Montero wrote: > Am 02.12.2026 um 13:47 schrieb David Brown: > >> Resuming the blocked threads in FIFO order of blocking is >> the norm in RTOS's, and is typically guaranteed by the OS. ... > > Show me a RTOS with a guarantee on the ordering of wakeups with mutexes. > It does't make sense since the behaviour of threads sharing the same > mutex largely depends on their locking- and unlocking-timing. From the ThreadX documentation on mutexes : """ After the same number of put operations are performed by the owning thread, the suspended threadโs get operation is performed, giving it ownership of the mutex, and the thread is resumed. If multiple threads are suspended on the same mutex, they are resumed in the same order they were suspended (FIFO). """ I only picked ThreadX, because I happen to be using it in a project at the moment, so I have the documentation open. Some other RTOS's will resume threads based on their priority, but if multiple threads of the same priority are waiting for the same mutex, they will be resumed in FIFO order. If thread 1 takes a mutex, and then threads 2, 3 and 4 all try to take it and block, then thread 1 releases the mutex, there are only two sensible real-time strategies for picking which blocked thread gets released. You either picked the thread that has been waiting longest (FIFO first), or you pick the blocked thread with the highest priority, and if there are multiple blocked threads with the same priority, pick the one that has been waiting longest. ThreadX uses the first of these (FIFO, always waking the thread that has waited longest), while FreeRTOS uses the later (use priority first, then FIFO if there are multiple waiting threads with the same priority). AFAIUI, real-time threads on Linux do this too, when using real-time mutexes. Most OS's are RTOS's, and that means such matters are documented and guaranteed. For common lock types on "big" systems, there is too much variation to be able to guarantee exact ordering without extra overheads. Such OS's may have additional effects they take into account - thread affinity to different cpus and caches, overall waiting times for a thread, expected run-times for the thread, etc. But if there are no overriding factors, I'd expect to see roughly - but not guaranteed - FIFO ordering.
Technical Details
Message-ID:
<11ep7lj$332tf$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11ep150$2vi4k$1@raubtier-asyl.eternal-september.org> <11ep418$3150m$1@dont-email.me> <11ep5b4$31rbr$1@raubtier-asyl.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: Why ordered mutexed don't work ... Date: Wed, 2 Dec 2026 14:49:38 +0100 Organization: A noiseless patient Spider Lines: 50 Message-ID: <11ep7lj$332tf$1@dont-email.me> References: <11ep150$2vi4k$1@raubtier-asyl.eternal-september.org> <11ep418$3150m$1@dont-email.me> <11ep5b4$31rbr$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 02 Dec 2026 13:49:39 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3247023"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zd7UxIWsg/hy3aTtkGDUGM7NdxJrxcHg="; posting-host="8f689f606fabca0b227a4c433cd7c78e" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:P7uPgkd6Pcbi1knRzKn9zJgtDkA= sha256:v5Kp9k5GzSvto5IGU8eqCHkRq1KKSnkMAyxMFgMW4tI= sha1:6400rKkaePEcOXbPjBnjzKXS3Uc= sha256:oxzOkMfFBwyhGAR9Jd0dp1W1kZXdoVi9yY3mMko1cSY= In-Reply-To: <11ep5b4$31rbr$1@raubtier-asyl.eternal-september.org> Content-Language: en-GB, nb-NO