Quoting Nicholas Miell:
PTHREAD_PROCESS_SHARED says any thread with access to the
memory containing the mutex can operate on the mutex and
POSIX basically ignores the idea that different processes
could be running completely incompatible executables or
whatever.
pthread_mutex_t has a bunch of #ifdefs in the middle of it
that change the structure size and layout between i386 and
x86_64.
Most importantly, the positions of the __nusers and __kind
fields are swapped (this looks to be an oversight dating
back to 2003 when __nusers was first introduced and carefully
preserved when the separate i386 and x86_64 versions of
pthreadtypes.h were merged into the single x86 version),
which means that when the lock and unlock functions attempt
to figure out what kind of mutex it is
(recursive/adaptive/whatever), they'll look at the wrong
field if the mutex is from the wrong architecture and then
things will break.
And then there's the fact that the rest of the struct is a
union in the 32-bit version and flat in the 64-bit version,
but that could have been worked around if you put a flag in
the __kind field that tells the 64-bit pthread library that
it is looking at a 32-bit mutex.
Reported-by: Nicholas Miell <nmiell@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>