> > I think that you may be using two different 
> CCriticalSection objects, in
> > which case you are not protecting anything.
> 
> I'm definitely using two different ones now; but surely they 
> each lock the
> thread they are running in from being interrupted, regardless 
> of whether
> they are one and the same object?

No, they just block themselves if the other thread is running. That is:

Let's suppose the following were to occur (assuming "CCriticalSection
m_crit" is in the class .h file):

<I am interspersing the two threads here to show you the exact order of
execution>

Thread 1: m_crit.Lock()
Thread 1: do stuff
Thread 2: m_crit.Lock() // This call doesn't return. Thread 2 is blocked
Thread 1: do more stuff
Thread 1: m_crit.Unlock()       // This unblocks thread 2.
Thread 2: do stuff
Thread 1: m_crit.Lock()         // This call doesn't return. Thread 1 is
blocked
Thread 2: do more stuff
Thread 2: m_crit.Unlock()       // This unblocks thread 1
Thread 1: do stuff
Thread 1: m_crit.Unlock()       // now no thread safe code should be
executed in either thread until the next lock.

If you use a different CCriticalSection object for each thread, then the
Lock() calls won't block.



Reply via email to