Article View: comp.lang.c
Article #2156Re: Why ordered mutexed don't work ...
From: Chris M. Thomasson
Date: Thu, 03 Dec 2026 21:57
Date: Thu, 03 Dec 2026 21:57
26 lines
2689 bytes
2689 bytes
On 12/3/2026 12:27 AM, Waldek Hebisch wrote: > Bonita Montero <Bonita.Montero@gmail.com> wrote: >> Just for fun, I tried writing a mutex today that wakes up threads >> in the same order they began waiting. I thought I was finished, but >> while cycling into the old town for a meal, it occurred to me: I can >> control the order in which threads start waiting, but I cannot control >> the order in which the scheduler wakes them up. Furthermore, if there >> isnโt a free CPU core available, thereโs no guarantee that a thread >> will be woken up immediately. Once I got home, well-fed, I deleted >> the entire project. > > AFAICS one can give resonable implementation in user space. > Of course code handling queue of waiting thread is a critical > section. so you need a mutex to protect it. To handle > suspending and waking up you need per thread semaphore. That reminds me of some old code that tried to emulate a condvar in Windows before it had it as a std feature. Some of them used per thread nodes for the waitqueue. Most of them were broken beyond broken. But the ones that were correct using manual wait queues were only SCHED_OTHER. Might as well use a fast pathed algo in userspace and allow the kernel to handle the real waitqueue only when it needs to. [...]>
Technical Details
Message-ID:
<11esojt$sus4$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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> <11er95v$3cgpa$1@paganini.bofh.team>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c Subject: Re: Why ordered mutexed don't work ... Date: Thu, 3 Dec 2026 13:57:13 -0800 Organization: A noiseless patient Spider Lines: 26 Message-ID: <11esojt$sus4$1@dont-email.me> References: <11ep150$2vi4k$1@raubtier-asyl.eternal-september.org> <11er95v$3cgpa$1@paganini.bofh.team> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 03 Dec 2026 21:57:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="949124"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19id2tOKnv8RJt36oU60CVYAZE+kPGWet8="; posting-host="27be630b90107ef0dd0e5ccb8f536ba4" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ySt1jlQGBCZTo55xnaI0YrNeP+k= sha256:i5fxtlrsa1Q4AnMLxBkVbeAFWJvD1J26f2j0SoZS38s= sha1:62aJCcIZ0AxAJXkORf/ZEbipDbs= sha256:avjKIxEV/RQiXwlhCAJzcAfX+xAFAKOylWwUFFo3SN8= In-Reply-To: <11er95v$3cgpa$1@paganini.bofh.team> Content-Language: en-US