Simple question: reading / writing a variable in multithreading
Hi guys. I've a too simple question.
I have an int variable which is accesed by two threads. One simply increases it at certain times, the other simply reads it's value.
Code:
// thread 1
m_MyVar++;
//thread 2
if(m_MyVar < MyOtherVar)
...
else
...
Should I implement a CCriticalSection or it's unnecessary??? I'm not sure what can happen when reading a variable whose value is being incremented, or perhaps this is an atomic affair?
Thanks in advance.
Re: Simple question: reading / writing a variable in multithreading
Re: Simple question: reading / writing a variable in multithreading
using this function InterLockedExchangeadd (variable, interval)
For example :
InterLockedExchangeadd (im_Counter ,1 );
Re: Simple question: reading / writing a variable in multithreading
Can't imagine how useful that's going to be!
Much thanks guys, you're great!