![]() |
|
Message-ID: <20250128150258.GS10433@brightrain.aerifal.cx> Date: Tue, 28 Jan 2025 10:02:58 -0500 From: Rich Felker <dalias@...c.org> To: Daniele Personal <d.dario76@...il.com> Cc: musl@...ts.openwall.com Subject: Re: pthread_mutex_t shared between processes with different pid namespaces 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
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.