Expanding from this question (How to do an atomic increment and fetch in C?)
In C, using Clang compiler, how can I do the atomic equivalent of
const int v = ++x
As I understand it, v = atomic_fetch_add(&x, 1)
will return the original value (ie v = x++
), which is a post-increment.
How do I return the updated value of x instead?
Note: this question is about C, and any replies with "use std::atomic<>" will be downvoted accordingly.