Sunday, June 7, 2015

Is there a robust mutex for interprocess locking?

This blog post is not something that shows you how to create a robust mutex for shared memory mutexes.
It tells you that if you're searching for one, then there is currently no reliable way to do it crossplatform.

If you're here, you'd already know that when a process acquires a lock and the process is killed by a user, the lock never gets unlocked and another process which is waiting to acquire the same lock, just keeps waiting.

Timed locks aren't reliable. File locking is not the way to go (but see this and this).

I did an extensive search and found that pthreads has the concept of a robust lock to solve the problem, but on trying it, the ordinary locking between processes itself is not working.


In Boost Interprocess:

Mr.Ion Gaztanaga has tried coming up with a crossplatform implementation for robust locking in Boost Interprocess, but still needs to test it fully on Windows.

If you want to take a hint on implementing it yourself, then Ion's code is the way to go.



In due time, this blog post will be outdated. Please do post the solution to the problem in the comments so that others can find it.


Btw, do you know what happens when  a foo walks into a bar? :-)

No comments: