Article View: comp.lang.c++
Article #305Re: Consequential RCU
From: Bonita Montero
Date: Mon, 12 Oct 2026 04:32
Date: Mon, 12 Oct 2026 04:32
113 lines
4980 bytes
4980 bytes
Am 12.10.2026 um 05:31 schrieb Chris M. Thomasson:
> Nice, 32 threads is a good load! Actually, can you tell me a bit more
> about what the test did? Mainly... did the shared pointer actually
> change during the run (and how often), and did anything check the
> results at the end, like total allocated vs. total freed?
static void timedTest( char const *what, auto fn, bool forTbl );
static void soTest( int type, bool forTbl )
{
constexpr sobj_mode Mode = sobj_mode::Hdr;
tshared_obj<string, Mode> tsoStr( make_shared_obj<string, Mode>( "hello
world" ) );
shared_obj<string, Mode> altStrs[2];
if( type == StoreAlt )
{
altStrs[0] = make_shared_obj<string, Mode>( "alt1" );
altStrs[1] = make_shared_obj<string, Mode>( "alt2" );
}
constexpr const char *Descr = "shared_obj: ";
switch( type )
{
case Load:
timedTest( Descr, [&]
{
thread_local shared_obj<string, Mode> soStr;
soStr = tsoStr;
}, forTbl );
break;
case Store:
timedTest( Descr, [&]
{
thread_local shared_obj<string, Mode> soStr = tsoStr;
tsoStr = soStr;
}, forTbl );
break;
case StoreAlt:
timedTest( Descr, [&]
{
thread_local bool flip = true;
tsoStr = altStrs[flip = !flip];
}, forTbl );
break;
case Xchg:
timedTest( Descr, [&]
{
thread_local shared_obj<string, Mode> soStr = tsoStr;
tsoStr.exchange( soStr );
}, forTbl );
break;
case Move:
timedTest( Descr, [&]
{
thread_local shared_obj<string, Mode> soStr;
if( !soStr )
soStr = move( tsoStr );
else
tsoStr = move( soStr );
}, forTbl );
}
}
static void timedTest( char const *what, auto fn, bool forTbl )
{
cout << what << endl;
vector<jthread> threads;
unsigned hc = jthread::hardware_concurrency();
threads.reserve( hc );
for( unsigned nThreads = 1; nThreads <= hc; ++nThreads )
{
latch lat( nThreads );
atomic_int64_t tSum( 0 ), roundsSum = 0;
atomic_bool stop( false );
for( unsigned t = 1; t <= nThreads; ++t )
{
threads.emplace_back( [&, fn = fn]()
{
lat.arrive_and_wait();
auto start = high_resolution_clock::now();
int64_t rnd = 0;
for( ; !stop.load( memory_order_relaxed ); ++rnd )
fn();
tSum += duration_cast<nanoseconds>( high_resolution_clock::now() -
start ).count();
roundsSum += rnd;
} );
#if defined(_WIN32)
SetThreadAffinityMask( threads.back().native_handle(), (DWORD_PTR)1
<< (t - 1) );
#endif
}
#if defined(NDEBUG)
constexpr duration TIME = 100ms;
#else
constexpr duration TIME = 100ms;
#endif
this_thread::sleep_for( TIME );
stop = true;
threads.resize( 0 );
double nsOp = (double)tSum / (double)roundsSum;
string result = (ostringstream() << nsOp).str();
replace_if( result.begin(), result.end(), []( char c ) { return c ==
'.'; }, ',' );
if( !forTbl )
cout << "\t" << nThreads << ": " << nsOp << endl;
else
cout << "\"" << result<< "\"" << endl;
}
}
But I'm pretty sure you don't understand the code since you didn't
understand the basic idea.
Technical Details
Message-ID:
<11ahnst$38s55$1@raubtier-asyl.eternal-september.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mailReferences:
<118f4vv$3plsv$1@dont-email.me> <11a0l38$150m3$1@raubtier-asyl.eternal-september.org> <11a0odn$16c2e$1@dont-email.me> <11a0tf5$18frd$1@raubtier-asyl.eternal-september.org> <11a4i3l$2i092$3@dont-email.me> <11a5fpa$2sm77$1@raubtier-asyl.eternal-september.org> <11a695o$370r9$3@dont-email.me> <11a749f$3fl36$2@raubtier-asyl.eternal-september.org> <11aea6s$23clj$2@dont-email.me> <11af538$2bhju$1@raubtier-asyl.eternal-september.org> <11agtqp$30rp8$1@dont-email.me> <11ahjij$37hnn$1@raubtier-asyl.eternal-september.org> <11ahkae$37oqq$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail From: Bonita Montero <Bonita.Montero@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: Consequential RCU Date: Mon, 12 Oct 2026 06:32:31 +0200 Organization: A noiseless patient Spider Lines: 113 Message-ID: <11ahnst$38s55$1@raubtier-asyl.eternal-september.org> References: <118f4vv$3plsv$1@dont-email.me> <11a0l38$150m3$1@raubtier-asyl.eternal-september.org> <11a0odn$16c2e$1@dont-email.me> <11a0tf5$18frd$1@raubtier-asyl.eternal-september.org> <11a4i3l$2i092$3@dont-email.me> <11a5fpa$2sm77$1@raubtier-asyl.eternal-september.org> <11a695o$370r9$3@dont-email.me> <11a749f$3fl36$2@raubtier-asyl.eternal-september.org> <11aea6s$23clj$2@dont-email.me> <11af538$2bhju$1@raubtier-asyl.eternal-september.org> <11agtqp$30rp8$1@dont-email.me> <11ahjij$37hnn$1@raubtier-asyl.eternal-september.org> <11ahkae$37oqq$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 12 Oct 2026 04:32:30 +0000 (UTC) Injection-Info: raubtier-asyl.eternal-september.org; logging-data="3436709"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PPk0qXmQ06VFJ9djh4Bas4YuVC/a4HzA="; posting-host="4c9ae59a7cd92f27485c546753e3700f" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:K81Gs9y7u09CQS/YQ+w/3QAFgwc= sha256:nBLcDXv2o1qDRXpULNcUfBOrEt3DWUuEoY9ieaaOeKk= sha1:wWmUm2u+yQbJRjJRrWzX9uVNGc8= sha256:TqVOEIc2SW2S+douXDBQvphcjYEfiNa6tPurvkps0+I= In-Reply-To: <11ahkae$37oqq$1@dont-email.me> Content-Language: de-DE