Click to See Complete Forum and Search --> : How come there isn't a thread safe way to read an int?


Rigel
August 27th, 2008, 03:44 PM
I was investigating using the ::InterlockedXXX family of functions but how come there isn't a thread safe way to read an int? What should be done if I want to read an int safely? Thank you

ishaypeled
August 27th, 2008, 04:27 PM
If you want to do anything safe with integers you should use mutexes or condition variables or monitors or any other means of synchronization.
The only method provided by the processor for synchronizing data is TSL, which can be used to implement the above methods (just think of the complication in implementing what you're requesting in hardware...)
Hope this helps,
Ishay Peled.