0

I use global mutex in multi-process in windows, however, the mutex won't be released when the owner process crashes, and then another process calls WaitForSingleObject, it returns WAIT_ABANDONED, how should I do to let this mutex relase, or do some other actions when returns WAIT_ABANDONED?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Gordon
  • 396
  • 2
  • 15
  • 1
    you take ownership of the mutex object after `WaitForSingleObject` return `WAIT_ABANDONED`. you not need any special actions in this case. – RbMm Oct 11 '18 at 08:03
  • and you wrong understand documentation. the mutex object of course **released**. otherwise you simply not got ownership for it. from doc *mutex object that was not released by the thread that owned the mutex object **before** the owning thread terminated*. so mutex is released **after** thread terminate by system itself. this is mean `WAIT_ABANDONED` – RbMm Oct 11 '18 at 08:09
  • 2
    Yes, however `WAIT_ABANDONED` indicates that since the mutex was not released gracefully by the owning thread, any shared resources being protected by the mutex are in an unknown and potentially unstable state and should not be trusted anymore, unless you have a way of recovering the data and resetting it to a known and stable state. – Remy Lebeau Oct 11 '18 at 12:07
  • See [Understanding the consequences of WAIT_ABANDONED](https://blogs.msdn.microsoft.com/oldnewthing/20050912-14/?p=34253) on MSDN: "*If the thread that owns a mutex exits without releasing the mutex, **the mutex is automatically released on the thread's behalf**. But if this happens, you're in big trouble. [WAIT_ABANDONED is typically treated] as a successful wait, because **it does mean that the object was obtained**, but it also tells you that the previous owner left the mutex abandoned and that the system had to release it on the owner's behalf.*" – Remy Lebeau Oct 11 '18 at 12:09

0 Answers0