2

I plan to use the WinApi CreateMutex function to only allow one running instance of my application. But I wonder what happens if the apps crashs. Is the created Mutex automatically released by the OS if the main process dies? I can't find an answer to this in the MS knowledgebase. TIA!

1 Answer 1

1

A mutex is a kernel object whose lifetime is controlled by its references. When a process terminates, however it terminates, all the references to kernel objects held by that process are removed. If this leaves a kernel object having no remaining references to it, that kernel object is destroyed.

2
  • The mutex will be destroyed when there are no more references to it. The issue is more complex when there are multiple processes with references to the mutex. You then need all the processes that have references to clear those references (either with a call to CloseHandle or by the process terminating). But suppose only a single process has a reference to the mutex. Then when that process ends, the mutex is destroyed. Jun 30, 2014 at 11:51
  • Thanks David, that answered my question. :-)
    – Chris
    Jun 30, 2014 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.