stdatomic Questions
2
Solved
There is a part in the C++ standard about multi-threading memory model that I don't understand.
A visible side effect A on a scalar object or bit-field M with respect to a value computation B of M...
Swinge asked 18/4, 2020 at 0:23
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
2
How does an atomic<shared_ptr<>> work internally ? I'm not asking for the mechanics of the control block alongside with the stored data, which is easy to imagine for me, but for the ato...
Gassy asked 6/8 at 11:35
0
Generally std::atomic<T> does not imply semantics of volatile, i.e. operations on the atomic object are not observable side effects that the compiler needs to preserve.
As a consequence the c...
Stopple asked 22/7 at 2:16
3
Solved
The following code prints whether std::atomic<bool> is trivially copyable:
#include <atomic>
#include <iostream>
#include <type_traits>
int main(){
std::cout << std:...
Seizing asked 25/4 at 13:13
1
Solved
libc++ std::counting_semaphore uses atomic increment with memory_order_release in release method:
void release(ptrdiff_t __update = 1)
{
if(0 < __a.fetch_add(__update, memory_order_release))
...
Cascade asked 2/8, 2020 at 11:27
4
Solved
atomic_flag_test_and_set Yes!
atomic_flag_clear Yes!
atomic_flag_test_and_clear nope
atomic_flag_set nope
If you wanted to do something like set a flag on a event in some context, and in some oth...
Nunez asked 2/2 at 19:15
4
Solved
I would like to generate identifiers for a class named order in a thread-safe manner. The code below does not compile. I know that the atomic types do not have copy constructors, and I assume that ...
4
Solved
std::array< std::atomic_size_t, 10 > A;
// ...
std::atomic_init(A, {0}); // error
A = {ATOMIC_VAR_INIT(0)}; // error
How would you initialize an array of std::atomic to 0s?
Even for loops up...
1
Solved
Let's say I have a struct Foo s. t.
struct alignas(64) Foo {
std::atomic<int> value;
Foo* other;
};
Then, if I have an array Foo array[2048]; of Foo's: I already have initialized the array...
Unalterable asked 24/11, 2023 at 12:14
1
Solved
I'm experimenting with C++ atomic's std::atomic<T>::is_always_lock_free and std::atomic<T>::is_lock_free.
I wrote a simple struct A and want to know if the atomic version of A is lock-f...
2
Solved
In the question How to use std::atomic<>, obviously we can just use std::mutex to keep thread safety. I want to know when to use which one.
struct A {
std::atomic<int> x{0};
void Add(...
Wooden asked 21/9, 2016 at 12:56
4
Solved
While porting some Windows C++ code to iOS, I need to provide an implementation of Win32's long InterlockedIncrement(long *p) call. This is easy enough using the functions defined in <libkern/OS...
4
Solved
I wanted to understand what does one mean by lock_free property of atomic variables in c++11. I did googled out and saw the other relevant questions on this forum but still having partial understan...
3
Solved
C++11 introduced the std::atomic<> template library. The standard specifies the store() and load() operations to atomically set / get a variable shared by more than one thread.
My question is...
3
Solved
I want to use an std::atomic_int variable. In my code, I have:
#include <atomic>
std::atomic_int stop = 0;
int main()
{
// Do something
}
And this gives me a compile error:
use of dele...
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
3
Solved
I have a function that accesses(reads and writes to) a std::atomic<bool> variable. I'm trying to understand the order of execution of instructions so as to decide whether atomic will suffice ...
Netherlands asked 5/10, 2016 at 9:26
2
Can atomic variables in C++11 be initialized globally?
For example:
std::atomic_int turnX = 5;
int main() {
/* ... */
}
This fails with:
error: deleted function ‘std::atomic<int>::atomic(co...
Latex asked 14/7, 2011 at 22:38
2
With current C++ compilers you can have atomic support of atomics that are larger than the actual support of your CPU. With x64 you can have atomics that are 16 bytes, but std::atomic also works wi...
3
Solved
Since it's Thanksgiving today in the USA, I'll be the designated turkey to ask this question:
Take something as innocuous as this. An atomic with a simple plain old data type such as an int:
atom...
Amaral asked 29/11, 2019 at 5:54
1
Solved
I know that the -latomic flag is required for the atomic library to be linked in by GCC. However, for some reason std::atomic<int> doesn't require it to build
build without latomic
while stru...
1
Solved
std::atomic has deleted copy assignment operators. Hence, the following results in a compiler error:
std::atomic<int> a1, a2;
a1 = a2; // Error
I think the motivation for the deleted operato...
Kremlin asked 17/7, 2023 at 12:54
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
7
Solved
In C++, there is one atomic type std::atomic<T>. This atomic type may be lock-free or maybe not depending on the type T and on the current platform. If a lock-free implementation for a type i...
Ietta asked 28/2, 2023 at 21:47
1 Next >
© 2022 - 2024 — McMap. All rights reserved.