memory-model Questions
1
Solved
#include <memory>
#include <atomic>
#include <iostream>
#include <thread>
#include <cassert>
int main()
{
std::atomic<bool> flag = {false};
std::atomic<int&...
Calan asked 19/9 at 14:22
1
Solved
Consider the following code, with adjacent mutex sections containing shared memory accesses:
std::mutex mutex;
int x;
void func() {
{
std::lock_guard lock{mutex};
x++;
}
{
std::lock_guard lo...
Captor asked 22/6 at 13:0
0
After a release operation A is performed on an atomic object M, the
longest continuous subsequence of the modification order of M that
consists of:
Writes performed by the same thread that perfor...
Vastha asked 10/9, 2023 at 11:57
2
Solved
(Assume: int x{ 6 } and 2 evaluations write x = 6 at the same time)
--
CPP reference says on Multi-threaded executions and data races | Data races:
When an evaluation of an expression writes to a ...
Adagio asked 3/9, 2023 at 10:8
2
Solved
TL:DR: if a mutex implementation uses acquire and release operations, could an implementation do compile-time reordering like would normally be allowed and overlap two critical sections that should...
Tumulus asked 19/4, 2020 at 4:51
1
Solved
Just when I thought I got some grip around atomics, I see another article. This is an excerpt from GCC wiki, under Overall Summary:
-Thread 1- -Thread 2- -Thread 3-
y.store (20); if (x.load() == ...
Reeducate asked 11/2, 2023 at 18:16
4
While reading the source codes of Go, I have a question about the code in src/sync/once.go:
func (o *Once) Do(f func()) {
// Note: Here is an incorrect implementation of Do:
//
// if atomic.Comp...
Yvor asked 28/1, 2021 at 10:18
6
Solved
I don't understand, why will be problems without release sequence, if we have 2 threads in the example below. We have only 2 operations on the atomic variable count. count is decremented sequently ...
Editor asked 25/7, 2016 at 10:43
0
In the following code
int a = A.load(std::memory_order_acquire);
T b = load_non_atomic(data);
// ---- barrier ----
int c = A.load(std::memory_order_acquire);
What kind of barrier should I use ...
Scarberry asked 14/10, 2022 at 12:43
2
Solved
Consider the following situation
// Global
int x = 0; // not atomic
// Thread 1
x = 1;
// Thread 2
if (false)
x = 2;
Does this constitute a data race according to the standard?
[intro.races] sa...
Keramic asked 9/6, 2022 at 14:2
1
Solved
I've read this Q&A: What is the significance of 'strongly happens before' compared to '(simply) happens before'?
The author gives an outline of an interesting evaluation that wa...
Zamia asked 24/5, 2022 at 22:57
4
Solved
I am currently reading C++ Concurrency in Action by Anthony Williams. One of his listing shows this code, and he states that the assertion that z != 0 can fire.
#include <atomic>
#include &...
Fishman asked 22/1, 2018 at 14:31
2
Solved
When it comes to implementing CAS Loop using std::atomic, cppreference in this link gives the following example for push:
template<typename T>
class stack
{
std::atomic<node<T>*>...
Majormajordomo asked 31/10, 2019 at 0:8
3
Solved
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...
Scarbrough asked 10/9, 2012 at 6:39
1
Solved
I read about Herb's atomic<> Weapons talk and had a question about page 42:
He mentioned that (50:00 in the video):
(x86) stores are much stronger than they need to be...
What I don't unde...
Frambesia asked 6/12, 2021 at 17:43
1
Solved
Consider the store buffer litmus test with SC atomics:
// Initial
std::atomic<int> x(0), y(0);
// Thread 1 // Thread 2
x.store(1); y.store(1);
auto r1 = y.load(); auto r2 = x.load();
Can th...
Hob asked 2/12, 2021 at 18:7
3
Solved
My understanding of std::memory_order_acquire and std::memory_order_release is as follows:
Acquire means that no memory accesses which appear after the acquire fence can be reordered to before the...
Sequestered asked 24/4, 2016 at 15:1
2
Solved
it make me confused, i reading golang memory model, https://golang.org/ref/mem
var l sync.Mutex
var a string
func f() {
a = "hello, world"
l.Unlock()
}
func main() {
l.Lock()
go f()...
Outrank asked 23/3, 2021 at 8:51
4
Solved
Many programming languages today have happens-before relation and release+acquire synchronization operations.
Some of these programming languages:
C/C++11: happens-before, release+acquire
Rust and...
Haughay asked 1/11, 2021 at 1:38
1
Solved
Consider this code:
std::atomic<int> x{ 0 };
std::atomic<int> y{ 0 };
int a;
int b;
void thread1()
{
//atomic op A
x.store(1, std::memory_order_relaxed);
//fence X
std::atomic_thr...
Sturdy asked 29/10, 2021 at 18:53
4
Solved
I was recently answering a question on the undefined behaviour of doing p < q in C when p and q are pointers into different objects/arrays. That got me thinking: C++ has the same (undefined) beh...
Torment asked 10/10, 2019 at 11:42
1
Solved
I've been studying the memory model and saw this (quote from https://research.swtch.com/hwmm):
Litmus Test: Write Queue (also called Store Buffer)
Can this program see r1 = 0, r2 = 0?
// Thread 1 /...
Galactometer asked 9/9, 2021 at 3:51
1
With ARMv8.3 a new instruction has been introduced: LDAPR.
When there is a STLR followed by a LDAR to a different address, then these 2 can't be reordered and hence it is called RCsc (release consi...
Bully asked 6/8, 2021 at 5:44
3
Solved
Learning golang on the way, I got a little confused when trying to understand the channel communications described in the memory model spec as below:
A send on a channel happens before the cor...
Saiga asked 19/10, 2017 at 4:5
3
I'm trying to compile and link a simple program to a DOS .com file using Turbo C compiler and linker. By that I try the simplest C-program I can think of.
void main()
{}
Are there command line a...
Sour asked 1/5, 2019 at 14:50
1 Next >
© 2022 - 2024 — McMap. All rights reserved.