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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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? 🙂