开发者

is boost::detail::atomic_count thread safe?

开发者 https://www.devze.com 2023-02-15 18:47 出处:网络
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(th开发者_开发百科en I could just use regular int variable)?

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(th开发者_开发百科en 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? :)

0

精彩评论

暂无评论...
验证码 换一张
取 消