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==..) ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).