Morning chaps. (or whatever whereever you are)
when threading, what are the operations (if any) that are naturally atomic and therefore do not require synchronisation?
e.g can you get away with a simple getter…
int getNum()
{
return num_;
}
where num_ can change at any time and this being called from another thread or will this one day go arse for tit and should be…
int getNum()
{
ScopedLock l ( critsec_ );
return num_;
}
or how about…
[code]int& getNum()
{
return num_;
}
// or
int* getNum()
{
return &num_;
}[/code]
and what if num_ was declared volatile? I understand all volatile does is say “Here Jimmy! Divvent be putting num_ into any processor registers by way of optimisation now!”
In fact any threading advice, I want to hear it!