I was looking for long time around to have a portable robust solution for multiprocessing synchronization. Who touche this things know that good solution are boost::iterprocess named sync sync objects. But .... When
When your process have a named_mutex
locked and your process die (there are many normal situations when process die, not just bug or others.) In that case a named_mutex
will remain in locked state. There were attempt to make a robust_mutex
in boost code done by Ion Gaztanaga: Ion Gaztanaga
Robust Emulation
He had a nice idea on how to resolve abandoning state check. Each process, in game, has its own lock file and while is alive it hold that file locked. Then Ion's robust_mutex
check, in case of failed lock attempt, current owner process lock file, and can determine if current mutex owner is alive or not. In case it is death mutex can be taken. The trick with file lock is nice idea cause file locks are unlocked by OS in case process die, and this seems to be well portable. This solution wraps base spin_mutex
and hold current owner process id in the internal field. I made intensive testing and found 2 big problems.
And here come my question : I'm proposing solution for both problems, and I wood like to have some pro opinion about it.