Marco
Marco

Reputation: 31

shared memory locking and process crash

I want try to understand better the problem of synchronization of shared memory. I have understood that interprocess synchronization can work differently on different operating system. The most difference is what's happening when a process that has locked the shared memory crash. Windows free locked named mutex after a process crash whereas linux don't free it. Can someone explain me better the problem and which are the vantages and disadvantages? How is possible under linux free a named mutex or a interprocess semaphore after a process crash? I have searched on internet but I didn't find someone that explain good the problems and the solutions.

I hope somebody can help me. Sorry for my English.

Upvotes: 3

Views: 1828

Answers (1)

Richard
Richard

Reputation: 109100

The advantage of Windows is that the waiting thread is freed to continue. The disadvantage is that it has no idea what the state of the shared memory is—the crashed process may have been part way through updates. (Windows indicates this by the wait on the mutex returning WAIT_ABANDONED rather than WAIT_OBJECT_0 (or offsets from these if waiting on multiple objects).

In practice the only safe thing to do is to reset the shared memory in some way (assuming that can be done meaningfully) or to fail.

Upvotes: 2

Related Questions