threading monitor efficacy

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have to ask a stupid question regarding Monitor.

Wait() and Pulse() make be used to wait for and signal events in a
given thread.

However, neither can be used until calling within a synchronized block
between calls to Enter() and Exit().

Am I missing something when I say that it seems useless to use this
facility to synchronize threading activities between 2 or more
threads?

Maybe an event is more appropriate than Monitor?
 
Mike said:
I have to ask a stupid question regarding Monitor.

Wait() and Pulse() make be used to wait for and signal events in a
given thread.

However, neither can be used until calling within a synchronized block
between calls to Enter() and Exit().

Am I missing something when I say that it seems useless to use this
facility to synchronize threading activities between 2 or more
threads?

Maybe an event is more appropriate than Monitor?

Actually, Monitor implements precisely the semantics of the synchronization
mechanisms in Java (Java didn't invent the concept either). Using Monitor
does require a different way of thinking about synchronization than using
primitives such as an Event.

I'm sure there must be C#/.NET examples, but you should be able to find
examples of a thread-safe queue in any decent Java book - the idioms used
there will translate directly to .NET.

-cd
 
Back
Top