look at this code:
int data=5;
void Thread1()
{
if(data==5)
{
//nothing
}
}
void Thread2()
{
if(data==2)
{
//nothing
}
}
in this case, do i need to use EnterCriticalSection/MutexLock before if(data==..) ?
If you are just reading the data then no locks required.
If you are writing the data AND you care about the order data is read then you need to use CS to make sure the ordering is correct. (Note if the object has a more complex state that is not updated in an atomic operation then you may care more about the ordering of reads/writes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With