Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::atomic<float>- std::atomic<double>-specializations

24 views
Skip to first unread message

Bonita Montero

unread,
Nov 3, 2019, 8:59:41 AM11/3/19
to
C++20 includes specializations for atomic<float> and atomic<double>.
Can anyone here for what practicsal purpose this should be good for?
The only purpose I can imagine is when I have a thread that changes
an atomic double or float asynchronouslsy at random points. But the
need this should be extremely rare.

Bo Persson

unread,
Nov 3, 2019, 10:07:52 AM11/3/19
to
Probably added for completeness, which is what design by committee gets
us. :-)

Can't see much use for atomic<signed char> or atomic_uint_fast16_t
either. And those were there already.


Bo Persson

Bonita Montero

unread,
Nov 3, 2019, 10:31:46 AM11/3/19
to
> Can't see much use for atomic<signed char> or atomic_uint_fast16_t
> either. And those were there already.

Maybe for the counter of a mutex on platforms which have small atomic
types?

Bo Persson

unread,
Nov 3, 2019, 1:07:18 PM11/3/19
to
But do we really need all of atomic_char, atomic_schar, atomic_uchar,
atomic_char8_t, atomic_int8_t, atomic_uint8_t, atomic_int_least8_t,
atomic_uint_least8_t, atomic_int_fast8_t, atomic_uint_fast8_t, and
atomic_bool?

And with C++20 we now also get atomic_signed_lock_free and
atomic_unsigned_lock_free which are "most efficient" (in an unspecified
way), and which may or may not be 8-bits wide.

Or could we manage with just a subset of 8-bit types? :-)


To be honest, I *can* see some advantage in that templated code could do

atomic<T> x;
++x;

and it just might work even for T being floating point. But that's about it.


Bo Persson


Chris M. Thomasson

unread,
Nov 4, 2019, 5:03:03 PM11/4/19
to
For fun, I have used a table of atomic<double> that fractal computation
threads would update. The size of the table was divisible by two (real,
imag) so one can take a complex number in the form of [0][1]. [2][3] is
another one... These numbers were used by another set of threads as
starting points for an iterated function system.

Chris M. Thomasson

unread,
Nov 4, 2019, 5:04:22 PM11/4/19
to
The table was a 1d array:

real, imag, real, imag, real, imag, ..., ...
0 new messages