Questions tagged [relaxed-atomics]
29 questions
3
votes
1 answer
std::memory_order_relaxed with fetch_add
I'm trying gain a deeper understanding of relaxed memory ordering. Per CPP reference, there is no synchronization, however atomicity is still guaranteed. Doesn't atomicity in this case require some form of sync, e.g. how does fetch_add() below…

user3882729
- 1,339
- 8
- 11
3
votes
1 answer
Example of misuse of std::memory_order::relaxed in C++ Standard [algorithms.parallel.exec/5 in n4713]
One of the examples of misuse of std::memory_order::relaxed in C++ Standard:
std::atomic x{0};
int a[] = {1,2};
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) {
x.fetch_add(1, std::memory_order::relaxed);
//…

HCSF
- 2,387
- 1
- 14
- 40
3
votes
3 answers
is std::atomic::fetch_add a serializing operation on x86-64?
Considering the following code:
std::atomic counter;
/* otherStuff 1 */
counter.fetch_add(1, std::memory_order_relaxed);
/* otherStuff 2 */
Is there an instruction in x86-64 (say less than 5 years old architectures) that would allow…

J.N.
- 8,203
- 3
- 29
- 39
3
votes
3 answers
What is the (slight) difference on the relaxing atomic rules?
After seeing Herb Sutters excellent talk about "atomic weapons" I got a bit confused about the Relaxed Atomics examples.
I took with me that an atomic in the C++ Memory Model (SC-DRF = Sequentially Consistent for Data Race Free) does an "acquire" on…

towi
- 21,587
- 28
- 106
- 187
2
votes
1 answer
C++: Which weak atomic to use for buffers that receive async. RDMA transfers?
The Derecho system (open-source C++ library for data replication, distributed coordination, Paxos -- ultra-fast) is built around asynchronous RDMA networking primitives. Senders can write to receivers without pausing, using RDMA transfers into…

Ken Birman
- 1,088
- 8
- 25
2
votes
2 answers
Cheaper alternative to std::atomic?
I have a class of objects in a multithreaded application where each thread can mark an object for deletion, then a central garbage collector thread actually deletes the object. The threads communicate via member methods that access an internal…

Desperado17
- 835
- 6
- 12
2
votes
1 answer
Atomic operations on a single variable
What are the possible final results for the variable x in the following C++ code fragment? (please answer based on what is allowed by the C++ standard and not what is currently available on different platforms)
// Inside Thread 0
std::atomic x…

Koosha
- 1,492
- 7
- 19
1
vote
1 answer
Relaxed atomics in x86
I have a couple of questions regarding relaxed atomics in x86 architecture:
If I understand correctly, all read/writes in types of up to 8 bytes are atomic by default. Thus, will there be any data race in the following code? Meaning, is there any…

Santiago
- 379
- 3
- 14
1
vote
0 answers
Compiler/Hardware optimizations of code and relaxed atomics
I've been listening to Herb Sutter's Atomic Weapons talk and there's a slide where he discusses released atomic variables and optimizations on code. My question has more to do with what compiler optimizations are allowed to do and what they are not.…

speed_of_light
- 66
- 1
- 6
1
vote
3 answers
A Minimum Ordering Requirement
Let x and y be two different variables of type std::atomic and assume that the current value of both of them is 1. What is a most relaxed set of ordering requirements so the the following code generates some output? (i.e., what should be used…

Koosha
- 1,492
- 7
- 19
0
votes
0 answers
Question regarding relaxed memory ordering and initialization of shared data
To preface, I do think this is a silly question but am confused about it.
I'm currently trying to understand the C++ memory model (particularly reordering with weaker order semantics) and have a question regarding the initialization of a shared…

bot654321
- 39
- 4
0
votes
2 answers
Are relaxed atomic store reordered themselves before the release? (similar with load /acquire)
I read in the en.cppreference.com specifications relaxed operations on atomics:
"[...]only guarantee atomicity and modification order
consistency."
So, I was asking myself if such 'modification order' would work when you are working on the same…

Juan JuezSarmiento
- 255
- 1
- 8
0
votes
1 answer
C++ countdown in CyclicBarrier going wrong using atomic variables [solutions without locks please]
I am trying to implement a cyclic barrier in C++ from scratch. Aim is to implement as conformant to Java implementation as possible. The class
reference is here. https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html
Now…

Anand Kulkarni
- 395
- 1
- 2
- 10
-2
votes
1 answer
When is it okay to do/use something that has unspecified behaviour?
In C++, there are things that come up that are somewhere between well-defined and undefined. Specifically, those are called implementation defined and unspecified. Right now, I'm interested in the unspecified stuff.
When is it okay to use such…

Michael Gazonda
- 2,720
- 1
- 17
- 33