• stand alone membars in C++...

    From Chris M. Thomasson@chris.m.thomasson.1@gmail.com to comp.lang.c++ on Fri Jan 2 13:05:41 2026
    From Newsgroup: comp.lang.c++

    Sometimes we do not need to make per variable membars. For instance the
    atomic logic for locking/unlocking a mutex can all be relaxed. BUT, we
    need to add in the right membars, so it tends to go like this: ___________________
    atomic_mutex_lock(); // all relaxed
    std::atomic_thread_fence(std::memory_order_acquire);

    {
    // critical section...
    }

    std::atomic_thread_fence(std::memory_order_release);
    atomic_mutex_unlock(); // all relaxed
    ___________________

    Its more of a SPARC way of thinking about where to place memory barriers.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Chris M. Thomasson@chris.m.thomasson.1@gmail.com to comp.lang.c++ on Fri Jan 2 13:14:47 2026
    From Newsgroup: comp.lang.c++

    On 1/2/2026 1:05 PM, Chris M. Thomasson wrote:
    Sometimes we do not need to make per variable membars. For instance the atomic logic for locking/unlocking a mutex can all be relaxed. BUT, we
    need to add in the right membars, so it tends to go like this: ___________________
    atomic_mutex_lock(); // all relaxed
    -a-a std::atomic_thread_fence(std::memory_order_acquire);

    -a-a-a-a {
    -a-a-a-a-a-a-a-a // critical section...
    -a-a-a-a }

    -a-a std::atomic_thread_fence(std::memory_order_release); atomic_mutex_unlock(); // all relaxed
    ___________________

    Its more of a SPARC way of thinking about where to place memory barriers.

    Some atomic lock algos need to have a damn #StoreLoad in the logic
    itself. Ala, Dekker's algorithm.
    --- Synchronet 3.21a-Linux NewsLink 1.2