🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #833

Re: How to write a semaphore with futexes

#833
From: Ross Finlayson
Date: Thu, 12 Nov 2026 19:35
39 lines
3131 bytes
On 11/12/2026 08:41 AM, boltar@caprica.universe wrote:
> On Wed, 11 Nov 2026 15:05:43 -0800
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> gabbled:
>> On 11/11/2026 2:47 PM, Bonita Montero wrote:
>>> Am 11.11.2026 um 23:12 schrieb Chris M. Thomasson:
>>>
>>>> I see. A fun failure on a sem_wait is EINTR.
>>>
>>> That's not a out of recources error and it is recoverable.
>>
>> Its scary though when people fail to know about it.
>
> Anyone who doesn't read the man page before they use an unfamiliar function
> frankly deserves what they get.
>


Here's one for you.

So, I want a MPSC queue, multiple-producer single-consumer queue,
producers on the order of 1000, with that appends to the queue push(),
push_back, pretty much must use compare-and-swap the only atomic
primitive on the chip, though for example with having a buffer and using
conditional-move after compare-and-swap to copy items into the buffer
then appending multiple items from the buffer atomically. Then, the
consumer, should have a non-blocking peek() and pop(), peek_front and
pop_front, that should return an error if EWOULDBLOCK, then that it can
park in a syscall when the queue's empty, so that it idles in park with
0% CPU. Then pushing items onto the queue should change it back to
non-blocking.

So, when it's running it should be un-blocked, and appends must be
non-blocking, when it's empty, then it should block to "park".

In C and C++ and in POSIX, how's this.



Technical Details
Message-ID: <0iGdnbMEEbSZiGv3nZ2dnZfqnPqdnZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
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>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 Nov 2026 19:35:32 +0000
Subject: Re: How to write a semaphore with futexes
Newsgroups: comp.lang.c++
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>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Thu, 12 Nov 2026 11:35:24 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <11d4q72$bdct$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <0iGdnbMEEbSZiGv3nZ2dnZfqnPqdnZ2d@giganews.com>
Lines: 39
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-orNsD3wkPpAKDxTNFM89kKKwU89V9EPAoFoc4gxr5ad3j1TGVRyuNm/RMXBrfQ1tMCsCdh+pNW20lzM!HDbCExVW714D8+S0sRSxOLWFE7BDhrj8QU5viw2vNgjgzDauwlrHPYheP7wuuot6K33xNs+wu6FA
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40