memory-model Questions
1
Solved
Imagine N threads running following simple code:
int res = num.fetch_add(1, std::memory_order_relaxed);
where num is:
std::atomic<int> num = 0;
Is it completelly safe to assume, that re...
Strew asked 11/2, 2019 at 21:29
3
I'm asking specifically in the memory-model sense. http://en.cppreference.com/w/cpp/atomic/memory_order
I'm asking because I want to know if I can use a std::memory_order_consume in the below:
mL...
Garbers asked 6/5, 2013 at 3:20
2
Solved
Given the following C program:
static char vals[ 2 ] = {0, 0};
int main() {
char *a = &vals[0];
char *b = &vals[1];
while( 1 ) {
SOME_STUFF()
// non-atomic operations in critical se...
Futile asked 19/11, 2018 at 22:50
2
Solved
The C++ memory model has relaxed atomics, which do not put any ordering guarantees on memory operations. Other than the mailbox example in C which I have found here:
http://www.open-std.org/jtc1/s...
Ethnic asked 6/5, 2014 at 6:27
4
Solved
In JLS, §17.4.5. Happens-before Order, it says that
A program is correctly synchronized if and only if all sequentially consistent executions are free of data races.
It only give us definitio...
Mullin asked 18/8, 2012 at 12:0
4
Solved
Similar to my previous question, consider this code
-- Initially --
std::atomic<int> x{0};
std::atomic<int> y{0};
-- Thread 1 --
x.store(1, std::memory_order_release);
-- Thread 2 --...
Cowfish asked 6/1, 2015 at 21:1
3
Solved
On the x86 architecture, stores to the same memory location have a total order, e.g., see this video. What are the guarantees in the C++11 memory model?
More precisely, in
-- Initially --
std::at...
Educatory asked 6/12, 2014 at 15:43
2
Solved
Code in question:
#include <atomic>
#include <thread>
std::atomic_bool stop(false);
void wait_on_stop() {
while (!stop.load(std::memory_order_relaxed));
}
int main() {
std::thread...
Settera asked 22/5, 2018 at 7:5
2
On x86, lock-prefixed instructions such as lock cmpxchg provide barrier semantics in addition to their atomic operation: for normal memory access on write-back memory regions, reads and writes are ...
Scherer asked 10/5, 2018 at 20:13
1
Solved
In WB-memory, a = b = 0
P1:
a = 1
SFENCE
b = 1
P2:
WHILE (b == 0) {}
LFENCE
ASSERT (a == 0)
It is my understanding, that neither the SFENCE or LFENCE are needed here.
Namely, since, for this m...
Id asked 21/4, 2018 at 15:36
1
In the C++ memory model, there is a total order on all loads and stores of all sequentially consistent operations. I'm wondering how this interacts with operations that have other memory orderings ...
Seisin asked 27/11, 2017 at 22:15
1
Solved
The C++ Standard says that RMW (Read-Modify-Write) operations on atomics will operate on the latest value of the atomic variable. Consequently using memory_order_relaxed with these operations won't...
Multivocal asked 6/11, 2017 at 17:29
6
Solved
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 anyth...
Unchain asked 13/10, 2017 at 1:9
2
Solved
Maybe it's just me, but the example in the man 2 page for membarrier seems pointless.
Basically, membarrier() is an asynchronous memory barrier that, given two coordinating pieces of code (let's c...
Interrogation asked 30/8, 2017 at 22:19
3
Solved
I am studying this site: https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync, which is very helpful to understand the topic about atomic class.
But this example about relaxed mode is hard to understa...
Psychosocial asked 6/9, 2017 at 2:12
1
Say, I create an object of type Foo in thread #1 and want to be able to access it in thread #3.
I can try something like:
std::atomic<int> sync{10};
Foo *fp;
// thread 1: modifies sync: 10 ...
Embank asked 15/8, 2017 at 14:0
2
Solved
Assume that we have the following code:
class Program
{
static volatile bool flag1;
static volatile bool flag2;
static volatile int val;
static void Main(string[] args)
{
for (int i = 0; i ...
Colous asked 15/4, 2010 at 11:51
6
Solved
Let's say you have a simple class like this:
class MyClass
{
private readonly int a;
private int b;
public MyClass(int a, int b) { this.a = a; this.b = b; }
public int A { get { return a; } ...
Coltish asked 19/3, 2015 at 13:42
6
Solved
I'm reading Joe Duffy's post about Volatile reads and writes, and timeliness, and i'm trying to understand something about the last code sample in the post:
while (Interlocked.CompareExchange(ref...
Ivon asked 17/10, 2009 at 8:15
3
Consider the following code snippet taken from Herb Sutter's talk on atomics:
The smart_ptr class contains a pimpl object called control_block_ptr containing the reference count refs.
// Thread A...
Rosenberg asked 24/12, 2014 at 3:42
2
Solved
Specifically, is there any effective difference between:
i = a.load(memory_order_acquire);
or
a.store(5, memory_order_release);
and
atomic_thread_fence(memory_order_acquire);
i = a.load(memo...
Exudate asked 11/2, 2017 at 14:51
1
Solved
Clearly, sequential consistent atomic operations differ in their valid observable behavior from acquire-release only operations in a valid C++ program. Definitions are given in the C++ standard (si...
Wart asked 25/1, 2017 at 18:4
3
public class TestHashRace
{
private int cachedHash = 0;
private readonly object value;
public object Value
{
get { return value; }
}
public TestHashRace(object value)
{
this.value = valu...
Gulosity asked 24/11, 2016 at 18:27
4
I have just seen Herb Sutter's talk: C++ and Beyond 2012: Herb Sutter - atomic<> Weapons, 2 of 2
He shows bug in implementation of std::shared_ptr destructor:
if( control_block_ptr->refs.fe...
Sapless asked 14/2, 2013 at 17:54
1
How memory is managed in ruby. For Ex: if we take the C program during execution, the following is the memory model. Similar to this
how memory is handled in ruby.
C:
__________________
| |
|...
Extrinsic asked 4/7, 2016 at 11:52
© 2022 - 2024 — McMap. All rights reserved.