Question

I am new to these concepts. But as i am going deeper in threading i am getting confused.

What is the significance of mutex, semaphore over autoresetevent.

Only difference i came to know with studies is that a mutex can perform across process operations. If this is the case why it does not have same method as Set, Reset, WaitOne.

Can we replace the AutoResetEvent with mutex and vice versa?

Please solve this puzzle.

Was it helpful?

Solution

Different concept - a Mutex is an exclusive token; only one person can have it; when they release it, somebody else can fight over it. An AutoResetEvent is a gate that allows exactly one person through before closing, and which is operated by a button that is separate to the queue of people wanting to go through. When they pass through the gate immediately closes.

OTHER TIPS

It depends.

In common, AutoResetEvent and Mutex can be replaced, AutoResetEvent.WaitOne = Mutex.WaitOne and AutoResetEvent.Set = Mutex.ReleaseMutex.

But they are different. You may mentioned that the Mutex has a "Release", which means you may "get" something while calling "WaitOne". The thing you may get is related to the thread which is calling.

You can call AutoResetEvent.Set in any thread. But you can only call Mutex.ReleaseMutex from the thread which is called Mutex.WaitOne and get the true as result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top