Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #123840

Re: std::atomic work as volatile, or not, I think not...

From "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups comp.lang.c++
Subject Re: std::atomic work as volatile, or not, I think not...
Date 2026-05-11 13:25 -0700
Organization A noiseless patient Spider
Message-ID <10tte0n$1dkib$1@dont-email.me> (permalink)
References (3 earlier) <10ts5ur$updt$2@dont-email.me> <10tscpt$3vdv3$1@dont-email.me> <10tse1h$11bk8$1@dont-email.me> <10tsrcj$4pi$1@dont-email.me> <10ttdjo$1daks$1@dont-email.me>

Show all headers | View raw


On 5/11/2026 1:19 PM, David Brown wrote:
> On 11/05/2026 17:08, boltar@caprica.universe wrote:
>> On Mon, 11 May 2026 13:20:17 +0200
>> David Brown <david.brown@hesbynett.no> gabbled:
>>> On 11/05/2026 12:59, boltar@caprica.universe wrote:
>>>> On Mon, 11 May 2026 11:02:19 +0200
>>>> The underlying implementation will be the same.
>>>
>>> <https://cppreference.com/cpp/thread#Semaphores>
>>> <https://cppreference.com/cpp/atomic/atomic>
>>>
>>> I don't know how you can see them as being similar, unless by "the 
>>> underlying mechanism" you mean memory accesses along with processor- 
>>> specific features like bus lock prefixes, load-locked/store- 
>>> conditional sequences, CAS operations, memory barrier instructions, etc.
>>
>> Nice cut and paste. Yes, I'm talking about the CPU level.
>>
>>> In particular, semaphores have blocking support - you can block until 
>>> a semaphore is available.  Atomics do not block, and are critical to 
>>> non-blocking algorithms.
>>
>> And? Semaphores don't have to block.
> 
> Of course you don't /have/ to block on a semaphore, but there's not much 
> use of them if you don't.  You might as well just use an atomic counter, 
> which is much cheaper.
> 
> You can't use an atomic object for blocking.  C++ has a nice interface 
> that appears to do so, but it's actually using a futex or similar 
> mechanism for the blocking.  

Yeah. "Ideally", the futex is 100% separated from the atomics wrt its 
blocking logic. Usually hashed tables of wait queues in the kernel or 
wherever. For an impl detail, say the atomic can use a pointer to itself 
as a means to hash itself into a waitqueue. Kind of akin to:

https://groups.google.com/g/comp.lang.c++/c/sV4WC_cBb9Q/m/SkSqpSxGCAAJ



> Remember, an atomic int takes 4 bytes of 
> space (on most platforms), just like an int, and a relaxed read or write 
> is just a normal load or store - something that can block needs queues 
> of blocked threads and OS calls.  They are different worlds.


[...]

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-10 21:51 -0700
  Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 08:25 +0200
    Re: std::atomic work as volatile, or not, I think not... boltar@caprica.universe - 2026-05-11 08:28 +0000
      Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 11:02 +0200
        Re: std::atomic work as volatile, or not, I think not... boltar@caprica.universe - 2026-05-11 10:59 +0000
          Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 13:20 +0200
            Re: std::atomic work as volatile, or not, I think not... Bonita Montero <Bonita.Montero@gmail.com> - 2026-05-11 13:22 +0200
              Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 13:00 -0700
            Re: std::atomic work as volatile, or not, I think not... boltar@caprica.universe - 2026-05-11 15:08 +0000
              Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 22:19 +0200
                Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 13:25 -0700
            Re: std::atomic work as volatile, or not, I think not... scott@slp53.sl.home (Scott Lurndal) - 2026-05-11 15:48 +0000
              Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 13:09 -0700
          Re: std::atomic work as volatile, or not, I think not... Bonita Montero <Bonita.Montero@gmail.com> - 2026-05-11 13:21 +0200
          Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 12:48 -0700
            Re: std::atomic work as volatile, or not, I think not... red floyd <no.spam.here@its.invalid> - 2026-05-11 21:04 -0700
              Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-14 00:35 -0700
        Re: std::atomic work as volatile, or not, I think not... cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-11 11:53 +0000
          Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 15:18 +0200
            Re: std::atomic work as volatile, or not, I think not... Bonita Montero <Bonita.Montero@gmail.com> - 2026-05-11 15:20 +0200
              Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 12:54 -0700
  Re: std::atomic work as volatile, or not, I think not... "Fred. Zwarts" <F.Zwarts@HetNet.nl> - 2026-05-11 11:46 +0200
    Re: std::atomic work as volatile, or not, I think not... David Brown <david.brown@hesbynett.no> - 2026-05-11 12:40 +0200
      Re: std::atomic work as volatile, or not, I think not... Chris Ahlstrom <OFeem1987@teleworm.us> - 2026-05-11 06:55 -0400
        Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-12 12:14 -0700
    Re: std::atomic work as volatile, or not, I think not... scott@slp53.sl.home (Scott Lurndal) - 2026-05-11 15:49 +0000
      Re: std::atomic work as volatile, or not, I think not... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-11 12:36 -0700

csiph-web