Questions tagged [stdatomic]

std::atomic is a class template in the C++11 Standard Library which provides atomic operations.

std::atomic is a class template in the C++11 Standard Library, defined in the <atomic> header. An atomic object of type std::atomic<X> provides member functions to perform atomic operations on its member of type X.

Like mutexes, atomic objects can be used for synchronization in multi-threaded C++ programs. Unlike mutexes or other locks, atomics can be used to build algorithms that allow concurrent readers and writers.

Atomics can even be used to build custom locking primitives (but that's usually a bad idea on systems with OS-supported locking functions that yield the CPU on contention).

Resources:

591 questions
-1
votes
1 answer

Release sequence code snippet giving random behaviour

I was working on one of the examples from the book Concurrency With Modern C++ by Rainer Grimm and I found this code snippet (edited somewhat to get better undestanding of the concept). The code snippet is related to top Release Sequence #include…
-1
votes
1 answer

Is it possible to achieve 2 lines of code to always occur in a order in a multithreaded program without locks?

atomic_compare_exchange_strong_explicit(mem, old, new, , ); ftruncate(fd, ); All I want is that these two lines of code always occur without any interference (WITHOUT USING LOCKS). Immediately after that CAS,…
Mihir Luthra
  • 6,059
  • 3
  • 14
  • 39
-1
votes
2 answers

Is frequently updating std::atomic data problematic?

Problem Assume static std::atomic dataX =0.0; defined in a cpp(Module) In that module two separate functions have been defined. These functions will be invoked and run by two threads independently,under the hood(within functions) two…
user7467325
-1
votes
1 answer

Does std::atomic guarantee initialization initialization of types like int, float etc to 0/0.0?

Does std::atomic guarantee the value of basic_type to be 0 / 0.0 (whichever is applicable) when created as a class member without being explicitely initialized for: int / uint / short / ushort / etc... and; float /…
Gizmo
  • 1,990
  • 1
  • 24
  • 50
1 2 3
39
40