memory-model Questions
4
Can anyone point to benchmark results comparing performance of C11/C++11 code using relaxed atomic operations (particularly memory_order_release and memory_order_acquire, but also memory_order_cons...
Minority asked 3/11, 2013 at 11:36
3
Solved
I took the example about std::memory_order_seq_cst from:
http://en.cppreference.com/w/cpp/atomic/memory_order
#include <thread>
#include <atomic>
#include <cassert>
std::atomic&...
Malissamalissia asked 24/2, 2018 at 13:48
3
Solved
cppreference.com provides this note about std::atomic_thread_fence (emphasis mine):
atomic_thread_fence imposes stronger synchronization constraints than an atomic store operation with the same ...
Outlay asked 12/7, 2018 at 22:12
5
In his great book 'C++ Concurrency in Action' Anthony Williams writes the following (page 309):
For example, on x86 and x86-64 architectures, atomic load operations are
always the same, whether...
Apostil asked 10/5, 2012 at 15:54
2
Solved
I've found questions (like this one) asking what [[carries_dependency]] does, and that's not what I'm asking here.
I want to know when you shouldn't use it, because the answers I've read all make ...
Haymow asked 21/11, 2013 at 16:47
3
The main reason for using atomics over mutexes, is that mutexes are expensive but with the default memory model for atomics being memory_order_seq_cst, isn't this just as expensive?
Question: Can...
Issuable asked 30/4, 2013 at 20:20
3
Solved
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 = Sequentiall...
Proportionate asked 9/6, 2013 at 21:29
1
I'm not an ARM expert but won't those stores and loads be subjected to reordering at least on some ARM architectures?
atomic<int> atomic_var;
int nonAtomic_var;
int nonAtomic_var2;
voi...
Progressive asked 28/11, 2019 at 12:36
3
Solved
I'm writing some lock-free code, and I came up with an interesting pattern, but I'm not sure if it will behave as expected under relaxed memory ordering.
The simplest way to explain it is using an...
Fania asked 14/8, 2013 at 4:22
2
-Thread 1-
y.store (20, memory_order_release);
x.store (10, memory_order_release);
-Thread 2-
if (x.load(memory_order_acquire) == 10) {
assert (y.load(memory_order_acquire) == 20);
y.store (10...
Bighorn asked 21/5, 2018 at 1:50
1
The phrase "strongly happens before" is used several times in the C++ draft standard.
For example: Termination [basic.start.term]/5
If the completion of the initialization of an object w...
Bonefish asked 22/11, 2019 at 1:23
3
Solved
I'm trying to understand these sections under the heading Release-Acquire ordering https://en.cppreference.com/w/cpp/atomic/memory_order
They say regarding atomic load and stores:
If an atomic ...
Thereabouts asked 20/9, 2019 at 3:13
3
C++20 includes specializations for atomic<float> and atomic<double>. Can anyone here explain for what practical purpose this should be good for? The only purpose I can imagine is when I...
Synonymous asked 3/11, 2019 at 14:5
2
Thread A runs x.store(1, std::memory_order_release) first,
then thread B runs x.load(std::memory_order_acquire).
x in thread B is not guaranteed to read 1 stored by A.
If I use memory_order_seq_c...
Prop asked 22/10, 2018 at 10:13
1
This could be a language neutral question, but in practice I'm interested with the C++ case: how are multithread programs written in C++ versions that support MT programming, that is modern C++ wit...
Iver asked 6/11, 2019 at 3:53
2
I have written a simple 'envelope' class to make sure I understand the C++11 atomic semantics correctly. I have a header and a payload, where the writer clears the header, fills in the payload, the...
Marj asked 24/9, 2019 at 22:35
5
Solved
Suppose I have 2 threads:
int value = 0;
std::atomic<bool> ready = false;
thread 1:
value = 1
ready = true;
thread 2:
while (!ready);
std::cout << value;
Is this program able to ou...
Aldon asked 29/10, 2016 at 14:46
1
Solved
Does volatile sig_atomic_t give any memory order guarantees? E.g. if I need to just load/store an integer is it ok to use?
E.g. here:
volatile sig_atomic_t x = 0;
...
void f() {
std::thread t([&...
Intricacy asked 14/6, 2019 at 13:14
2
Consider the following code:
struct payload
{
std::atomic< int > value;
};
std::atomic< payload* > pointer( nullptr );
void thread_a()
{
payload* p = new payload();
p->value.st...
Marvamarve asked 20/6, 2015 at 7:57
3
Solved
If I lock a std::mutex will I always get a memory fence? I am unsure if it implies or enforces you to get the fence.
Update:
Found this reference following up on RMF's comments.
Multithreaded pr...
Lucia asked 23/6, 2012 at 20:56
1
Solved
When reading about consistency models (namely the x86 TSO), authors in general resort to models where there are a bunch of CPUs, their associated store buffers and their private caches.
If my unde...
Glean asked 8/5, 2019 at 23:10
2
Solved
I'm checking how the compiler emits instructions for multi-core memory barriers on x86_64. The below code is the one I'm testing using gcc_x86_64_8.3.
std::atomic<bool> flag {false};
int any...
Proffer asked 18/3, 2019 at 23:42
1
Solved
The current draft of the C++ standard (march 2019) has the following paragraph ([basic.types] p.4) (emphasis mine):
The object representation of an object of type T is the sequence of N unsigned...
Darling asked 18/3, 2019 at 16:7
1
Solved
Consider the diagrammed data cache architecture. (ASCII art follows.)
--------------------------------------
| CPU core A | CPU core B | |
|------------|------------| Devices |
| Cache A1 | Ca...
Aguedaaguero asked 11/2, 2019 at 19:9
1
Solved
I see that g++ generates a simple mov for x.load() and mov+mfence for x.store(y).
Consider this classic example:
#include<atomic>
#include<thread>
std::atomic<bool> x,y;
bool r1...
Mydriatic asked 12/2, 2019 at 14:46
© 2022 - 2024 — McMap. All rights reserved.