Article View: comp.lang.c++
Article #865Re: How to write a semaphore with futexes
From: Chris M. Thomasson
Date: Sun, 15 Nov 2026 00:43
Date: Sun, 15 Nov 2026 00:43
21 lines
2497 bytes
2497 bytes
On 11/13/2026 6:44 AM, Joseph Seigh wrote: [...] > It's unlikely anyone has program logic that requires FIFO, what little > of it is actually observable. You really care about forward progress > guarantees. As long as the consumer keeps up with the producers, you > should be ok doing batches in LIFO order. If not, you have other > problems. > > And if you drop the FIFO requirement then you could just have multiple > consumers doing XCHG on the queue tail pointer. > If the "FIFO" was removed, then its _really_ easy: No DWCAS, a standard LIFO stack, the single consumer takes them all. Does its work. There is no ABA, no deferred reclamation. It just works. And for waiting on empty conditions? eventcount, or a futex with a wait bit for the node pointers. Also, like you said FIFO wrt MP is basically iffy anyway.
Technical Details
Message-ID:
<11dav7t$2cuon$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cvher$2ahke$1@raubtier-asyl.eternal-september.org> <11d02gm$2h8g0$1@dont-email.me> <11d145g$2qlhs$1@raubtier-asyl.eternal-september.org> <11d2p9c$3eke4$1@dont-email.me> <11d2r97$3f9sa$2@raubtier-asyl.eternal-september.org> <11d2sca$3fn5d$1@dont-email.me> <11d4q72$bdct$1@dont-email.me> <0iGdnbMEEbSZiGv3nZ2dnZfqnPqdnZ2d@giganews.com> <11d55rp$8hhb$1@dont-email.me> <11d566l$8mlf$1@dont-email.me> <11d77og$tk4f$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!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: How to write a semaphore with futexes Date: Sat, 14 Nov 2026 16:43:38 -0800 Organization: A noiseless patient Spider Lines: 21 Message-ID: <11dav7t$2cuon$1@dont-email.me> References: <11cvher$2ahke$1@raubtier-asyl.eternal-september.org> <11d02gm$2h8g0$1@dont-email.me> <11d145g$2qlhs$1@raubtier-asyl.eternal-september.org> <11d2p9c$3eke4$1@dont-email.me> <11d2r97$3f9sa$2@raubtier-asyl.eternal-september.org> <11d2sca$3fn5d$1@dont-email.me> <11d4q72$bdct$1@dont-email.me> <0iGdnbMEEbSZiGv3nZ2dnZfqnPqdnZ2d@giganews.com> <11d55rp$8hhb$1@dont-email.me> <11d566l$8mlf$1@dont-email.me> <11d77og$tk4f$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 15 Nov 2026 00:43:42 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2521879"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XOdlJj7fpE4K1+cMzWwfoopkAsFKhCSo="; posting-host="8d4bfe82b7f7bce740ab6d5ca121f681" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:992+QXTFCaUlMdNYAaIkU4mQKjE= sha256:mH+ZGPBq5piHVs7v77WAv8WCSe6q45M/7qw786REak0= sha1:plhnhjPGLbqP+9a5Ywth6TcjcIA= sha256:tcC8rpn3vNrgvh7xv6vintMX19ogXJHDZof80kDDXSQ= Content-Language: en-US In-Reply-To: <11d77og$tk4f$1@dont-email.me>