Two threads are accessing my Synclocked code

  • Thread starter Thread starter Joel Moore
  • Start date Start date
J

Joel Moore

I'm looking at my debugger right now and can clearly see that two threads
have their execution pointer residing within the same Synclock block.

One thread is executing a Monitor.Wait(). I know this suspends the thread
but I didn't think this would open the gate for other threads to enter the
block.

Any ideas what could be happening?

Joel Moore
 
I'm looking at my debugger right now and can clearly see that two
threads have their execution pointer residing within the same Synclock
block.

One thread is executing a Monitor.Wait(). I know this suspends the
thread but I didn't think this would open the gate for other threads
to enter the block.

Any ideas what could be happening?

Joel Moore

And just to clarify some, here is a snippet of code from the MSDN sample
that I derived my own code from. It's the Serial LCD sample:

lock (responseSignal)
{
responsePacket = null;
// comPort
com.Write(packetXMitBuffer, 0, dataLength + 4);
if (Monitor.Wait(responseSignal, MAX_RESPONSE_TIME))
{
return responsePacket;
}
}

Elswhere there is a Receive() thread that Pulses the Monitor once the COM
port receives enough data.

After doing a little more reading it seems that the Monitor.Wait() does
release the lock which would imply that this sample code is faulty, no?
Seems like I'd need to use a seperate object for the Monitor.Wait() call
than what was used to lock the code.
 
Which object are synchronising on and are you sure you are synchronising on
the same instance for all threads?
 
Back
Top