1

As described in this question, use of boost's interprocess_mutex and interproces condition_variable may result in a deadlock if the process holding the mutex crashes.
This is because boost's mutex is not a kernel object and therefore is not automatically released when the process holding it exits. Is there a way in boost to use interprocess conditional variables with the mutex returned by a call to CreateMutex?

David Sackstein
  • 500
  • 1
  • 5
  • 19
  • See https://stackoverflow.com/questions/1179685/how-do-i-take-ownership-of-an-abandoned-boostinterprocessinterprocess-mutex/1179766#1179766 – sehe Jul 11 '17 at 23:50
  • Thanks for the pointer. An interprocess mechanism that does not handle a crash in one of the processes? I would have expected better from boost. – David Sackstein Jul 12 '17 at 08:57
  • TBH it's application defined what should be the behaviour. Unless the OS supports robust IPC synchronization mechanisms, which I doubt. And if it does: use that ... :( – sehe Jul 12 '17 at 17:14

1 Answers1

0

Just use CreateSemaphore() directly to implement condvars across multiple processes. You don't need to use Boost condvars. Windows provides a very rich set of well defined, fairly correct, named machine-wide synchronisation objects. Use those instead.

Niall Douglas
  • 9,212
  • 2
  • 44
  • 54
  • Implementing condvars is not a simple matter and involves much more than calling CreateSemaphore. – David Sackstein Jul 13 '17 at 17:01
  • Boost.Thread's condvar implementation is implemented on win32 using win32 semaphores which are not broken like the POSIX ones. Simply clone that implementation. Should be done within an hour. – Niall Douglas Jul 13 '17 at 19:57
  • Boost.Interprocess author here. Using semaphores will not fix the issue. If a process dies while using a semaphore implementing a condition variable, the other process won't notice it. The exception are named mutexes, that can return WAIT_ABANDONED when the owner dies. Semaphores, by definition, have no owner, so if a process is waiting another one to signal a semaphore and the signaller dies, there is no notification by the kernel. – igaztanaga Aug 25 '21 at 09:31