stdatomic - Accessing uninitialized atomic private variable in c++ -
supposed have following class:
class { public: ... ... void incrementn() {++n_;} uint64_t getn() {return n_;} private: std::atomic<uint64_t> n_; ... ... };
assume initialize other variables in class, except n_
, not thread local storage, there no 0 initialization.
i create object of class a, , keep calling incrementn()
.
if @ point want value of n_
, , call getn()
, can cause load()
routine atomic n_
crash?
the load uses memory_order_seq_cst default. see here: http://en.cppreference.com/w/cpp/atomic/memory_order.
as mentioned in comments, shouldn't give problems normal ints won't give. concerned overflow if uninitialised initial value large? see here possible consequences: https://www.owasp.org/index.php/integer_overflow
Comments
Post a Comment