title: Locking mechanisms for shared-memory consistency
body: <p>I'm developing a mechanism for interchanging data between two or more processes using shared memory on linux. The problem is some level of concurrency control is required to maintain data integrity on the shared memory itself, and as I'm expecting that sometime or another my process could be killed/crash, common lock mechanisms don't work because they could left the memory in a &quot;locked&quot; state and right after dying, making other processes hung waiting for the lock to be released.</p>
  <p>So, doing some research I've found that System V semaphores have a flag called SEM_UNDO which can revert the lock state when the program fails, but that's not guaranteed to work. Another option is to monitor the PID's from all processes that might use the shared memory and do some control over them if something nasty happens, but I'm not so sure if this might be the right approach to my problem.</p>
  <p>Any ideas?</p>
  <p>Edit: for explanation purposes, our app need some kind of IPC mechanism with the smallest latency possible. So, I'm open for mechanisms that can handle this requirement also.</p>