Thread View: comp.lang.c++
5 messages
5 total messages
Started by Bonita Montero
Tue, 17 Nov 2026 05:22
I did it ...
Author: Bonita Montero
Date: Tue, 17 Nov 2026 05:22
Date: Tue, 17 Nov 2026 05:22
42 lines
2492 bytes
2492 bytes
I used a goto:
bool xshared_mutex::exclusive_to_shared( x2s_mode bias )
{
uint64_t ref = m_atomic.load( memory_order_relaxed );
thread_id recoverThreadId = m_exclusiveId.load( memory_order_relaxed );
m_exclusiveId.store( thread_id(), memory_order_relaxed );
bool rdBias = (m_readerBias.load( memory_order_relaxed ) || (int)bias >
0) && (int)bias >= 0;
uint64_t watingExclMask = rdBias ? 0 : WaitingExclusiveMask, wakeups;
for( ; ; )
{
assert(check( ref ));
assert(ref & ExclusiveFlag);
if( (ref & watingExclMask) )
{
if( (ref & WaitingSharersMask) == WaitingSharersMask )
goto err;
uint64_t niu = ref - WaitingExclusiveValue + WaitingSharersValue;
if( !m_atomic.compare_exchange_strong( ref, niu,
memory_order_release, memory_order_relaxed ) )
continue;
releaseExclusive();
waitShared();
return true;
}
wakeups = (ref >> WaitingSharersBase) & Mask21;
if( wakeups == Mask21 )
goto err;
uint64_t niu = (ref & ~XclWtShrMask) + wakeups + SharerValue;
if( m_atomic.compare_exchange_strong( ref, niu, memory_order_release,
memory_order_relaxed ) )
break;
}
if( wakeups )
releaseShared( (unsigned)wakeups );
return true;
err:
m_exclusiveId.store( recoverThreadId, memory_order_relaxed );
return error<bool>();
}
Re: I did it ...
Author: Chris M. Thomasson
Date: Wed, 18 Nov 2026 00:07
Date: Wed, 18 Nov 2026 00:07
48 lines
3241 bytes
3241 bytes
On 11/16/2026 9:22 PM, Bonita Montero wrote:
> I used a goto:
>
> bool xshared_mutex::exclusive_to_shared( x2s_mode bias )
> {
> uint64_t ref = m_atomic.load( memory_order_relaxed );
> thread_id recoverThreadId =
> m_exclusiveId.load( memory_order_relaxed );
> m_exclusiveId.store( thread_id(), memory_order_relaxed );
> bool rdBias = (m_readerBias.load( memory_order_relaxed ) ||
> (int)bias > 0) && (int)bias >= 0;
> uint64_t watingExclMask = rdBias ? 0 : WaitingExclusiveMask, wakeups;
> for( ; ; )
> {
> assert(check( ref ));
> assert(ref & ExclusiveFlag);
> if( (ref & watingExclMask) )
> {
> if( (ref & WaitingSharersMask) == WaitingSharersMask )
> goto err;
> uint64_t niu = ref - WaitingExclusiveValue +
> WaitingSharersValue;
> if( !m_atomic.compare_exchange_strong( ref, niu,
> memory_order_release, memory_order_relaxed ) )
> continue;
> releaseExclusive();
> waitShared();
> return true;
> }
> wakeups = (ref >> WaitingSharersBase) & Mask21;
> if( wakeups == Mask21 )
> goto err;
> uint64_t niu = (ref & ~XclWtShrMask) + wakeups + SharerValue;
> if( m_atomic.compare_exchange_strong( ref, niu,
> memory_order_release, memory_order_relaxed ) )
> break;
> }
> if( wakeups )
> releaseShared( (unsigned)wakeups );
> return true;
> err:
> m_exclusiveId.store( recoverThreadId, memory_order_relaxed );
> return error<bool>();
> }
>
For fun, when you are bored and have nothing to do... Model it in
Relacy! :^)
Re: I did it ...
Author: Bonita Montero
Date: Wed, 18 Nov 2026 04:18
Date: Wed, 18 Nov 2026 04:18
7 lines
1527 bytes
1527 bytes
Am 18.11.2026 um 01:07 schrieb Chris M. Thomasson: > For fun, when you are bored and have nothing to do... Model it in > Relacy! :^) You would even recomment to use relacy for a hello world.
Re: I did it ...
Author: Chris M. Thomasson
Date: Wed, 18 Nov 2026 07:01
Date: Wed, 18 Nov 2026 07:01
13 lines
1792 bytes
1792 bytes
On 11/17/2026 8:18 PM, Bonita Montero wrote: > Am 18.11.2026 um 01:07 schrieb Chris M. Thomasson: > >> For fun, when you are bored and have nothing to do... Model it in >> Relacy! :^) > > You would even recomment to use relacy for a hello world. > ;^D Well, if your threads filled buffers with "hello world" and sent them back to another thread that printed them out on the screen... Its fun to use race detectors.
Re: I did it ...
Author: Lynn McGuire
Date: Fri, 20 Nov 2026 04:43
Date: Fri, 20 Nov 2026 04:43
49 lines
3207 bytes
3207 bytes
On 11/16/2026 11:22 PM, Bonita Montero wrote:
> I used a goto:
>
> bool xshared_mutex::exclusive_to_shared( x2s_mode bias )
> {
> uint64_t ref = m_atomic.load( memory_order_relaxed );
> thread_id recoverThreadId =
> m_exclusiveId.load( memory_order_relaxed );
> m_exclusiveId.store( thread_id(), memory_order_relaxed );
> bool rdBias = (m_readerBias.load( memory_order_relaxed ) ||
> (int)bias > 0) && (int)bias >= 0;
> uint64_t watingExclMask = rdBias ? 0 : WaitingExclusiveMask, wakeups;
> for( ; ; )
> {
> assert(check( ref ));
> assert(ref & ExclusiveFlag);
> if( (ref & watingExclMask) )
> {
> if( (ref & WaitingSharersMask) == WaitingSharersMask )
> goto err;
> uint64_t niu = ref - WaitingExclusiveValue +
> WaitingSharersValue;
> if( !m_atomic.compare_exchange_strong( ref, niu,
> memory_order_release, memory_order_relaxed ) )
> continue;
> releaseExclusive();
> waitShared();
> return true;
> }
> wakeups = (ref >> WaitingSharersBase) & Mask21;
> if( wakeups == Mask21 )
> goto err;
> uint64_t niu = (ref & ~XclWtShrMask) + wakeups + SharerValue;
> if( m_atomic.compare_exchange_strong( ref, niu,
> memory_order_release, memory_order_relaxed ) )
> break;
> }
> if( wakeups )
> releaseShared( (unsigned)wakeups );
> return true;
> err:
> m_exclusiveId.store( recoverThreadId, memory_order_relaxed );
> return error<bool>();
> }
Do you want me to send you a few thousand of gotos?
Lynn
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads