Oleg Vazhnev
Oleg Vazhnev

Reputation: 24057

std::atomic<int> - load and reset to 0 atomically?

Having std::atomic<int> how can I atomically load value and reset to 0? So If I do this operation from two threads, only one receive value, another should receive 0.

Upvotes: 5

Views: 2463

Answers (1)

AlexD
AlexD

Reputation: 32566

std::atomic<int> x = 1;
int y = x.exchange(0);

Upvotes: 13

Related Questions