Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Unix weanies are as bad at this as anyone. -- Larry Wall in <199702111730.JAA28598@wall.org>


devel / comp.lang.c++ / futephore

SubjectAuthor
o futephoreBonita Montero

1
futephore

<uv8h77$1ljat$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3573&group=comp.lang.c%2B%2B#3573

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: futephore
Date: Thu, 11 Apr 2024 13:23:23 +0200
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <uv8h77$1ljat$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 11 Apr 2024 13:23:19 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="60f5ab8b13164cf87238791110f9e482";
logging-data="1756509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Hn0cCodWHGWPBLt/LC3W/Au0Zzgk/d7k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:76AR2VfOlAEgixD4iilxsOUhHpE=
Content-Language: de-DE
 by: Bonita Montero - Thu, 11 Apr 2024 11:23 UTC

I tried to implement a counting semaphore with a futex and that's my
csolution:

// header:

#include <atomic>

struct futephore
{ futephore() noexcept;
void wait() noexcept;
void notify( uint32_t n );
private:
std::atomic_uint32_t m_releases;
};

inline futephore::futephore() noexcept :
m_releases( 0 )
{ }

// cpp

#include <system_error>
#include "futephore.h"

using namespace std;

void futephore::wait() noexcept
{ for( uint32_t before = m_releases.load( memory_order_relaxed ); ; )
if( before )
if( m_releases.compare_exchange_strong( before, before - 1,
memory_order_acquire, memory_order_relaxed ) )
break;
else
continue;
else
m_releases.wait( 0, memory_order_relaxed ),
before = m_releases.load( memory_order_relaxed );
}

void futephore::notify( uint32_t n )
{ for( uint32_t before = m_releases.load( memory_order_relaxed ); ; )
if( before + n >= before )
if( m_releases.compare_exchange_strong( before, before + n,
memory_order_release, memory_order_relaxed ) )
break;
else
continue;
else
throw system_error( (int)errc::result_out_of_range,
generic_category(), "trying to release futefore beyond UINT32_MAX" );
for( ; n; --n, m_releases.notify_one() );
}


devel / comp.lang.c++ / futephore

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor