We help IT Professionals succeed at work.

Question about mutex.

MichaelMaromm
on
Hi,
I had used a mutex in my program, the thread released it by ReleaseMutex API function.
Now the mutex is signaled (WaitForSingleObject(...) returns WAIT_OBJECT_0).

My question is : How to turn it back to be non signaled ?

 Thanks
 Michael
Comment
Watch Question

jkr
BRONZE EXPERT
Top Expert 2012

Commented:
>>My question is : How to turn it back to be non signaled ?

If you called "WaitForSingleObject()" and it returned "WAIT_OBJECT_0", the state of the mutex actually _is_ non-signaled. Calling the "WaitForSingleObject()" from the same thread again would cause a deadlock.
>> How to turn it back to be non signaled ?
I guess you ask for "ReleaseMutex(hMutex)"

When the mutex is "available for grabbing" i.e. not owned) it's state is signaled. As soon as a thread owns it (due to a satisfied WaitForXxxxObject), it's nonsignaled). To make it signaled again(so others can grab it), use ReleaseMutex.


jkr: Calling the "WaitForSingleObject()" from the same thread again won't cause a deadlock, the wait will be satisfied immediately. Only you need to make sure you call ReleaseMutex as often as you got a satisfied WaitForSingleObject on this handle (from this thread)

jkr
BRONZE EXPERT
Top Expert 2012

Commented:
peterchen - that's how I understood the question: " had used a mutex in my program, the thread released it by ReleaseMutex API function"
jkr
BRONZE EXPERT
Top Expert 2012

Commented:
>>(from this thread)

Oops, you're right, I missed that part  :o)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.