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.

463 questions
2188
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
  • 353,942
  • 115
  • 666
  • 851
105
votes
3 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
90
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
  • 4,037
  • 13
  • 49
  • 64
81
votes
2 answers

What does the [[carries_dependency]] attribute mean?

Can someone explain it in a language that mere mortals understand?
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
69
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
  • 464,522
  • 92
  • 875
  • 1,084
61
votes
3 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
  • 228,013
  • 71
  • 433
  • 510
59
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
  • 51,233
  • 8
  • 91
  • 143
52
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
  • 4,286
  • 3
  • 32
  • 35
48
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 Stack Overflow 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++…
ciamej
  • 6,918
  • 2
  • 29
  • 39
45
votes
2 answers

Acquire/Release versus Sequentially Consistent memory order

For any std::atomic where T is a primitive type: If I use std::memory_order_acq_rel for fetch_xxx operations, and std::memory_order_acquire for load operation and std::memory_order_release for store operation blindly (I mean just like resetting…
zahir
  • 1,298
  • 2
  • 15
  • 35
38
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
  • 13,796
  • 3
  • 40
  • 68
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
  • 46,370
  • 69
  • 194
  • 251
35
votes
1 answer

C++11 memory_order_acquire and memory_order_release semantics?

http://en.cppreference.com/w/cpp/atomic/memory_order, and other C++11 online references, define memory_order_acquire and memory_order_release as: Acquire operation: no reads in the current thread can be reordered before this load. Release…
Cedomir Segulja
  • 417
  • 1
  • 4
  • 6
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,026
  • 2
  • 13
  • 29
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
  • 28,205
  • 28
  • 128
  • 277
1
2 3
30 31