Boost logo

Boost :

Subject: Re: [boost] Interprocess mutex & condition variable at process termination
From: Josh Juran (jjuran_at_[hidden])
Date: 2017-02-18 04:19:07

On Feb 16, 2017, at 7:31 AM, Phil Endecott via Boost <boost_at_[hidden]> wrote:

> Maybe, though my next concern would be how to implement the functionality
> of a condition variable. What happens if a process crashes while it
> is waiting on a condition variable? I did once know how Linux
> implements condition variables using atomics and futexes, and I
> think it's probably safe to crash in this situation, but I guess
> there are no guarantees.

I recently developed an application which uses a process-shared condition variable to coordinate graphics updates between an "author" and one or more "viewer" processes. I found that on Linux, not only was killing a viewer while it was waiting on the condition variable harmless, but killing and relaunching the author (which reinitialized the mutex and CV) had no adverse effect -- the application continued to work. It's undefined behavior, of course, so I was pleasantly surprised.

By contrast, the OS X I tested on doesn't even appear to be POSIX-conforming. Not only does relaunching the viewer after killing it mid-wait cause failures in the viewer *and* the tester (as one could at least anticipate, if not hope for), but a second viewer launched while the first was still waiting failed in pthread_cond_wait() (returning EINVAL), thus effectively limiting Apple's implementation of process-shared condition variables to two processes.

So yeah, no guarantees.


Boost list run by bdawes at, gregod at, cpdaniel at, john at