문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top