المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Atomicity in C#



C# Programming
05-17-2013, 12:12 AM
I am programming a bit counter, a method that returns a List < int > of the positions of the bits that are "on" in a UInt32. I was reviewing the code when I encountered
position--; bit >>= 1;To my mind these two statements need to be atomic. To achieve at least the notion of atomicity in C#, I would change the code to
position--; bit >>= 1;I am fiercely against this in a statement body. But in this case I think it signals atomicity. Is there a better way to do this?
Gus Gustafson