I'm incrementing/decrementing boost::detail::atomic_count in multiple threads.
Wonder if this practice is ok or if I need a lock around it(then I could just use regular int variable)?
Thank you.
The entire purpose of an atomic variable is to be lock-free* and thread-safe.
So yes, it's perfectly safe; no, you don't need a lock.
*That is, the "lock" is done at hardware level. Are you using something without understanding it first? :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.