Implementing cross-process locks
pijul.org
pijul.org
https://stackoverflow.com/questions/2389353/do-pthread-mutex...
I wonder if using a pthread mutex in shared memory is faster than flock'ing the file (I'd assume yes, though I don't know if significant).
Instead, file locks would be released by the kernel, and if you use a separate process as described in the post it is isolated enough that the chance of crashing/being killed by the kernel is low, and if that happens you can detect it and crash everything.
In general, there is no robust solution for inter-process synchronization in Linux, except file locks which have very limited functionality. It's quite sad, this is the kind of functionality that you'd expect the kernel to provide, instead we have to resort to workarounds like the one described here, which add operational complexity.
I'm not saying it's impossible, but you're basically implementing a distributed, embedded version of the lock daemon. And as all distributed things, fault-tolerance is hard. It's easier in a dedicated process or in the kernel because they're centralized (and if the kernel panics all processes stop; that can be emulated in a daemon).
(Ironic that you said there is no "robust" solution. They are also exposed via pthread_mutex as a robust attribute.)
But no one really uses robust futexes. Why? I think the problem of distributed co-ordination is fundamentally complex, and people prefer to deal with complexity they create than trying to understand other complex solutions. (I'm not saying that this bias is wrong.)
So it's a bit sad that you're sad about the kernel not providing something that is does indeed provide!
Futexes are a low-level primitive, I was talking about high-level primitives such as mutexes, condvars, and semaphores. If nobody has succeeded in implementing them on top of robust futexes, for practical purposes it's as if they don't exist.
Someone is being hopelessly optimistic about how reliable disk writes are.