Title: Re: [msvc] Best way of accessing functions..

Hi Ehsan ,
 Thanks for the below.

If for example I have a global class :

CExample List;

void CExample ::Increase()
{
  m_Variable++; //this is  variable declared in header
  if(m_Variable==20)
   AfxMessageBox("reached..");
}

void CExample ::SetValue(int Value)
{
      m_Variable=Value;
}

The above is just an example, but if my main thread was accessing
Increase(), and the OnTimer() called Clear(), it seems possible for the
m_Variable to access the variable the during the Increase routine from my
main thread. I want to make sure only 1 function is accessed at a time,

Neil

----- Original Message -----
From: "Ehsan Akhgari" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 07, 2003 7:58 AM
Subject: RE: [msvc] Best way of accessing functions..


> >   I have a global class that gets used with events from iexplorer,
> > which works fine. But I have one of the functions called within the
> > same global class during the OnTimer(..) which resets some of the
> > variables. What is the best way of making sure that the variables are
> > not getting modified by the two parts of the application? I tried
> > using CCriticalSection, but didnt work, then realised it protects
> > the sections from different threads.
> >
> > Anyone any ideas the best way of doing this?
>
> You seem not to want to protect the variable from access by several
> threads.  If this is true, then the variables are already safe, because
> if they're only accessed by one single thread, you don't need any
> synchronization.
>
> I'm puzzled in what you mean by 'parts' of application, if you're not
> talking of threads, though.
>
> -------------
> Ehsan Akhgari
>
> List Owner: [EMAIL PROTECTED]
>
> [ Email: [EMAIL PROTECTED]; [EMAIL PROTECTED] ]
> [ WWW: http://www.beginthread.com/Ehsan ]
>
> Whoever fights monsters should see to it that in the process he does not
> become a monster. And when you look long into the abyss, the abyss also
> looks into you. -Beyond Good And Evil, F. W. Nietzsche
>
>


Reply via email to