Possible Duplicate:
Do I need to use locking with integers in c++ threads
Do critical sections inside trivial int accessors actually do anything useful?
int GetFoo()
{
CriticalSection(crit_id);
return foo;
}
void SetFoo(int value)
{
CriticalSection(crit_id);
foo = value;
}
Is it possible for two threads to be attempting to read and write foo simultaneously? I'd have thought 'no' unless integers are written byte-at-a-time, in which case I can see the use. But I'd have though modern cpus would read/write integers in a single atomic action...