![]() |
|
Message-ID: <2501542748b57f9a3344dedc1b3376b1ecbeb856.camel@gmail.com> Date: Tue, 28 Jan 2025 17:13:21 +0100 From: Daniele Personal <d.dario76@...il.com> To: Rich Felker <dalias@...c.org> Cc: musl@...ts.openwall.com Subject: Re: pthread_mutex_t shared between processes with different pid namespaces On Tue, 2025-01-28 at 10:02 -0500, Rich Felker wrote: > On Tue, Jan 28, 2025 at 02:22:31PM +0100, Daniele Personal wrote: > > Hello everyone, > > I'm working on a library linked by some processes in order to > > exchange > > information. Such library uses some pthread_mutex_t instances to > > safely > > read/write the information to exchange: the mutexes are created > > with > > the PTHREAD_PROCESS_SHARED and PTHREAD_MUTEX_ROBUST attributes and > > shared through shared memory mmapped by the processes. > > > > Now, for certain reasons, I have to run one of the processes in a > > container and I found that, after a random interval of time, the > > process in the container got stuck in a pthread_mutex_lock without > > any > > reason. > > > > After some investigation I figured out that if the container is > > started > > without pid namespace isolation everithing works like a charm. > > > > So the questions: is the pid namespace isolation a problem when > > working > > with shared mutexes or should I investigate in other directions? > > If the problem is pid namespace isolation, what could be done to > > make > > it working apart from sharing the same pid namespace? > > > > The actual development is based on musl 1.2.4 built with Yocto > > Scarthgap for aarch64 and arm. > > Yes, the pid namespace boundary is your problem. Process-shared > mutexes only work on the same logical system with a unique set of > thread identifiers. If you're trying to share them across different > pid namespaces, the same pid/tid may refer to different > processes/threads in different ones, and it's not usable as a mutex > ownership identity. > > If you want robust-mutex-like functionality that bridges pid > namespaces, sysv semaphores are probably your only option. > > Rich Oh, thanks for clarifying it. But at a first glance at man 2 semop I see: Each semaphore in a System V semaphore set has the following associated values: unsigned short semval; /* semaphore value */ unsigned short semzcnt; /* # waiting for zero */ unsigned short semncnt; /* # waiting for increase */ pid_t sempid; /* PID of process that last modified the semaphore value */ Could it be that also sysv semaphores don't like different pid namespaces? If so, the only chance is to use the same pid namespace, isn't it? Daniele.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.