If I'm getting it right, is it possible in the Linux pthread C API to use robust mutexes, that can be shared across processes (by placing them in shared memory), and that allows you to acquire the lock if the proces previously holding it has crashed. However, I wondered if this could lead to problems when assignind PIDs to processes.
For instance, assume I am creating two processes, synchronizing with a mutex:
+-----------+ +-----------+
| Process 1 | +-----------+ | Process 2 |
| PID 1000 | | Mutex | | PID 1001 |
+-----------+ +-----------+ +-----------+
| | |
| lock | |
+------------>| |
| unlock | |
|------------>| lock |
| |<-------------|
| | released |
| |<- - - - - - -X
| | +-----------+
| | | Process 3 |
| | | PID 1001 |
| | +-----------+
| | lock |
| |<---------------------------|
| | ^ |
| | | |
| | HERE |
then, process 2 crashes, so the mutex should get released, but then a new process 3 spawns up, and it is assigned the same PID of process 2 (extremely unlikely given Linux policy, but technically possible I guess?). In this case, is the mutex correctly freed? If process 3 tries to lock it again, what happens? And if it is process 1 trying to lock?