• I did it ...

    From Bonita Montero@3:633/10 to All on Tue Nov 17 06:22:31 2026
    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>();
    }


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Nov 17 16:07:08 2026
    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! :^)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Wed Nov 18 05:18:35 2026
    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.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Nov 17 23:01:55 2026
    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.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lynn McGuire@3:633/10 to All on Thu Nov 19 22:43:16 2026
    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


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)