threading monitor efficacy

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?
 
C

Carl Daniel [VC++ MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top