Questions tagged [memory-model]

For questions on memory ordering models at the programming language level (above the ISA or machine language level).

For questions on memory ordering models at the programming language level (above the ISA or machine language level). If the question is about a specific language, use also the tag for that language. Otherwise, if the question is not about any specific language or if the question is on the implementation of a memory ordering model in a language translation tool, use other tags such as language-agnostic, programming-languages, language-design, bytecode, compilation, or other related tags, as suitable. A very relevant tag is memory-fences, but the tags are not exactly synonyms.

Do not use this tag for questions on the memory ordering models that are strictly at the ISA or microarchitecture level unless pertinent (e.g, when implementing a memory ordering model for language in a compiler that targets a particular architecture). Instead, the memory-order tag should be used for such questions.

393 questions
2023
votes
8 answers

C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?

C++11 introduced a standardized memory model, but what exactly does that mean? And how is it going to affect C++ programming? This article (by Gavin Clarke who quotes Herb Sutter) says that, The memory model means that C++ code now has a…
Nawaz
  • 327,095
  • 105
  • 629
  • 812
76
votes
2 answers

What does the [[carries_dependency]] attribute mean?

Can someone explain it in a language that mere mortals understand?
Yakov Galka
  • 61,035
  • 13
  • 128
  • 192
74
votes
5 answers

c++, std::atomic, what is std::memory_order and how to use them?

Can anyone explain what is std::memory_order in plain English, and how to use them with std::atomic<>? I found the reference and few examples here, but don't understand at all. http://en.cppreference.com/w/cpp/atomic/memory_order
2607
  • 3,557
  • 12
  • 45
  • 62
63
votes
4 answers

How do "acquire" and "consume" memory orders differ, and when is "consume" preferable?

The C++11 standard defines a memory model (1.7, 1.10) which contains memory orderings, which are, roughly, "sequentially-consistent", "acquire", "consume", "release", and "relaxed". Equally roughly, a program is correct only if it is race-free,…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
63
votes
2 answers

What do each memory_order mean?

I read a chapter and I didn't like it much. I'm still unclear what the differences is between each memory order. This is my current speculation which I understood after reading the much more simple…
user34537
58
votes
4 answers

What does `std::kill_dependency` do, and why would I want to use it?

I've been reading about the new C++11 memory model and I've come upon the std::kill_dependency function (§29.3/14-15). I'm struggling to understand why I would ever want to use it. I found an example in the N2664 proposal but it didn't help much. It…
R. Martinho Fernandes
  • 209,766
  • 68
  • 412
  • 492
50
votes
1 answer

Is writing a reference atomic on 64bit VMs

The java memory model mandates that writing a int is atomic: That is, if you write a value to it (consisting of 4 bytes) in one thread and read it in another, you will get all bytes or none, but never 2 new bytes and 2 old bytes or such. This is not…
Steffen Heil
  • 3,958
  • 3
  • 29
  • 33
46
votes
1 answer

What are the similarities between the Java memory model and the C++11 memory model?

The new c++ standard introduces the notion of a memory model. There were already questions on SO about it, what does it mean, how does it change the way we write code in c++ and so on. I'm interested in getting to know how does the C++ memory model…
ciamej
  • 6,263
  • 2
  • 25
  • 37
46
votes
4 answers

How do memory_order_seq_cst and memory_order_acq_rel differ?

Stores are release operations and loads are acquire operations for both. I know that memory_order_seq_cst is meant to impose an additional total ordering for all operations, but I'm failing to build an example where it isn't the case if all the…
AProgrammer
  • 48,232
  • 8
  • 83
  • 139
36
votes
7 answers

What is the C++03 memory model for concurrency?

What is the memory model for concurrency in C++03? (And, does C++11 change the memory model to support concurrency better?)
yesraaj
  • 42,284
  • 65
  • 185
  • 246
34
votes
6 answers

Can modern x86 hardware not store a single byte to memory?

Speaking of the memory model of C++ for concurrency, Stroustrup's C++ Programming Language, 4th ed., sect. 41.2.1, says: ... (like most modern hardware) the machine could not load or store anything smaller than a word. However, my x86 processor, a…
thb
  • 11,861
  • 3
  • 35
  • 63
33
votes
3 answers

Is synchronizing with `std::mutex` slower than with `std::atomic(memory_order_seq_cst)`?

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 concurrent a program using locks be as fast as…
jaybny
  • 1,016
  • 2
  • 13
  • 28
32
votes
3 answers

How can C++ compilers support C++11 atomic, but not support C++11 memory model

While looking at Clang and g++ C++11 implementation status I noticed something strange: they support C++11 atomics, but they dont support C++11 memory model. I was under impression that you must have C++11 memory model to use atomics. So what…
NoSenseEtAl
  • 23,776
  • 22
  • 102
  • 222
31
votes
3 answers

Does std::mutex create a fence?

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 programming and memory visibility
Tom Kerr
  • 9,632
  • 1
  • 26
  • 43
30
votes
3 answers

Is Dalvik's memory model the same as Java's?

Is Dalvik's memory model the same as Java's? I am particularly interested in whether reads and writes of reference and non-long/non-double primitive variables are atomic, but I would also like to know whether there are any differences between the…
Daniel Trebbien
  • 35,770
  • 14
  • 104
  • 182
1
2 3
26 27