简体   繁体   English

boost :: detail :: atomic_count线程安全吗?

[英]is boost::detail::atomic_count thread safe?

I'm incrementing/decrementing boost::detail::atomic_count in multiple threads. 我在多个线程中递增/递减boost :: detail :: atomic_count。
Wonder if this practice is ok or if I need a lock around it(then I could just use regular int variable)? 想知道这种做法是否可行,或者我是否需要锁定(然后可以使用常规的int变量)?

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? 您是否在使用某些东西之前不了解它? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM