I have two questions about atomism:
1) Is the following code a guarantee of the return of consecutive monotonically increasing sequences without duplicates in a multi-threaded setup?
#include <atomic>
struct AtomicCounter {
std::atomic<int> value;
AtomicCounter() : value( 0 ) {}
int getNextSequence(){
return ++value;
}
};
2) Is there an easier way to initialize? None of this succeeded:
std::atomic<int> value ( 0 ) ;
std::atomic<int> value { 0 } ;
std::atomic<int> value=0;
Thanks in advance
source
share