Re: PTHREAD_PROCESS_SHARED on GNU/Linux
- From: Steve Watt <steve.removethis@xxxxxxxx>
- Date: Sat, 24 Mar 2007 18:31:41 +0000 (UTC)
In article <ud52ysjvw.fsf@xxxxxxxxxxx>,
Raoul Gough <raoulgough@xxxxxxxxxxx> wrote:
I've been looking at potential problems if a process exits while
holding a lock on a mutex in shared memory (using
PTHREAD_MUTEX_SHARED). From what I understand (see e.g. [1] and [2]
below), a stock Linux kernel won't release the lock on behalf of the
dead process. This would prevent any other process from acquiring the
mutex, so you'd probably have to stop everything and re-initialize the
shared memory if any process dies unexpectedly.
Why would you want to do anything besides reinitialize the shared
memory region? If a process dies unexpectedly while holding a mutex,
the mere fact that it was holding a mutex indicates that there's
some invariant broken inside the shared memory region. If all the
invariants are intact, there shouldn't be a mutex held.
So this leads me to think that PTHREAD_MUTEX_SHARED is not useful
where reliability of the multiple processes is important. System V
semaphores (with the SEM_UNDO flag) would be preferable, even though
they are slower than mutexes in my testing (on a Linux 2.4.x kernel
with NPTL). I'm kind of assuming this would be the same in the 2.6
kernel series.
Automatic releasing of mutexes at process death is more harmful to
operating long-lived systems than leaving them locked. If the
mutex is left locked, and the developer didn't code for the
possibility that a process could die while holding the mutex and
write appropriate recovery code, then the system will fail
immediately, as opposed to magically unlocking the mutex, and
having the code assume that whatever's in the shared memory region
is OK when it's really subtly (or not so subtly) trashed. You'll
know instantly instead of some hours or days later.
From a brief look at [3], I can't tell whether POSIX requires thekernel to release a processes' locks - is this spelt out anywhere?
It makes no such requirement, because it's a bad idea.
Does anyone have experience with using shared mutexes on Linux, or is
it generally just avoided?
Correctly working process-shared mutexes are relatively new to Linux,
so they're not particularly widely used. But then, shared memory
isn't particularly widely used, either. Host people start with a
message passing interface (often sockets or pipes) for their IPC
needs, and that suffices for a large percentage of the problem space.
--
Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.5" / 37N 20' 15.3"
Internet: steve @ Watt.COM Whois: SW32-ARIN
Free time? There's no such thing. It just comes in varying prices...
.
- Follow-Ups:
- Re: PTHREAD_PROCESS_SHARED on GNU/Linux
- From: Raoul Gough
- Re: PTHREAD_PROCESS_SHARED on GNU/Linux
- References:
- PTHREAD_PROCESS_SHARED on GNU/Linux
- From: Raoul Gough
- PTHREAD_PROCESS_SHARED on GNU/Linux
- Prev by Date: Re: Multiple Threads vs. Asynchronous IO
- Next by Date: Re: PTHREAD_PROCESS_SHARED on GNU/Linux
- Previous by thread: PTHREAD_PROCESS_SHARED on GNU/Linux
- Next by thread: Re: PTHREAD_PROCESS_SHARED on GNU/Linux
- Index(es):
Relevant Pages
|