stdatomic Questions

2

Consider the following example code where thread A pushes functions on a queue and thread B executes those when popping from the queue: std::atomic<uint32_t> itemCount; //Executed by thread ...
Heid asked 4/1, 2021 at 1:13

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...

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

1

I just wanted to test if my compiler recognizes ... atomic<pair<uintptr_t, uintptr_t> ... and uses DWCASes on it (like x86-64 lock cmpxchg16b) or if it supplements the pair with a usual l...
Uxorious asked 19/9, 2021 at 16:42

1

Solved

I have the following code: #include <atomic> int main () { std::atomic<uint32_t> value(0); value.fetch_add(1, std::memory_order::relaxed); static_assert(std::atomic<uint32_t>:...
Despicable asked 17/11, 2021 at 5:34

4

Can anyone tell me whether std::atomic<T>::is_lock_free() isn't static as well as constexpr? Having it non-static and / or as non-constexpr doesn't make sense for me. Why wasn't it designed l...
Chaotic asked 12/11, 2019 at 10:0

2

Solved

Given the following sample that intends to wait until another thread stores 42 in a shared variable shared without locks and without waiting for thread termination, why would volatile T or std::ato...
Winstead asked 24/3, 2021 at 21:52

0

How should C++ code access memory that is shared with another application, e.g. through a memmapd file? The options seem to be: Regular raw accesses, e.g. int* p = ...address of shared memor...
Dragoman asked 22/7, 2021 at 3:3

1

Solved

I have a simple code: #include <atomic> int main() { std::atomic<int> a = 0; } This code compiles fine with GCC 11.1.0 with -std=c++17, but fails with -std=c++14 and -std=c++11. usi...
Tripoli asked 10/7, 2021 at 13:43

1

Solved

With reference to the following code auto x = std::atomic<std::uint64_t>{0}; auto y = std::atomic<std::uint64_t>{0}; // thread 1 x.store(1, std::memory_order_release); auto one = y.loa...
Upland asked 25/5, 2021 at 18:28

2

Solved

I'm looking for an alternative to std::atomic_ref which might be used without needing C++20 support. I've considered casting pointers to std::atomic but that does not seem like a safe option. The u...
Mattah asked 20/5, 2021 at 12:57

2

Solved

I've read https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange Atomically compares the object representation (until C++20)value representation (since C++20) of *this with that of expec...
Deaton asked 5/3, 2021 at 14:3

2

Solved

Consider two threads, T1 and T2, that store and load an atomic integer a_i respectively. And let's further assume that the store is executed before the load starts being executed. By before, I mean...
Omniscient asked 4/2, 2021 at 22:16

3

Solved

From the link: What is the difference between load/store relaxed atomic and normal variable? I was deeply impressed by this answer: Using an atomic variable solves the problem - by using atomics a...
Etter asked 17/12, 2020 at 7:38

1

Solved

The paper N4455 No Sane Compiler Would Optimize Atomics talks about various optimizations compilers can apply to atomics. Under the section Optimization Around Atomics, for the seqlock example, it ...
Lentz asked 23/11, 2020 at 21:3

1

Solved

According to cppreference, c++20 has rich (and, to me useful) support for atomic_flag operations. However, it's not clear whether gcc yet supports these features, they're not anywhere to be found o...
Holmium asked 19/11, 2020 at 15:30

2

Solved

I'd like to write a function that is accessible only by a single thread at a time. I don't need busy waits, a brutal 'rejection' is enough if another thread is already running it. This is what I ha...
Bascom asked 17/11, 2020 at 22:0

1

I watched this Herb Sutter talk: https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-2-of-2 Around the 1:25 mark, he talks about why the decrement of an atomic...
Dustydusza asked 16/10, 2020 at 3:48

2

Solved

I had a problem with a static assert. The static assert was exactly like this: static_assert(std::atomic<bool>::is_always_lock_free); and the code failed on Raspberry Pi 3 (Linux raspberrypi...
Conium asked 7/10, 2020 at 10:23

1

Solved

I was reading about [[carries_dependency]] in this SO post. But what I could not understand is the below sentences in the accepted answer : "In particular, if a value read with memory_order_c...
Squander asked 29/9, 2020 at 5:9

3

Solved

As I see from a test-case: https://godbolt.org/z/K477q1 The generated assembly load/store atomic relaxed is the same as the normal variable: ldr and str So, is there any difference between relaxed ...
Ifill asked 9/9, 2020 at 11:5

1

Solved

Suppose I have several threads accessing the same memory location. And, if at all, they all write the same value and none of them reads it. After that, all threads converge (through locks) and only...
Marden asked 25/8, 2020 at 17:39

2

If T is a C++ fundamental type, and if std::atomic<T>::is_lock_free() returns true, then is there anything in std::atomic<T> that is wait-free (not just lock-free)? Like, load, store, f...
Deedradeeds asked 17/5, 2020 at 9:58

2

Solved

I was looking through 'Atomic operations library' and came across a new c++20 feature of atomic 'wait' and 'notify_' methods. I am curious on what the differences are in regards to std::condition_v...
Airlift asked 12/7, 2020 at 9:56

1

Solved

In C++20 we can write: double x; double x_value = std::atomic_ref(x).load(); Is there a function with the same effect? I have tried std::atomic_load but there seem to be no overloads for non-atom...
Archilochus asked 1/7, 2020 at 5:57

© 2022 - 2024 — McMap. All rights reserved.