September 10th, 2004 09:14 AM
#1
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.
September 10th, 2004 04:32 PM
#2
Re: Simple question: reading / writing a variable in multithreading
September 13th, 2004 12:55 AM
#3
Re: Simple question: reading / writing a variable in multithreading
using this function InterLockedExchangeadd (variable, interval)
For example :
InterLockedExchangeadd (im_Counter ,1 );
September 13th, 2004 09:37 AM
#4
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!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks