1
votes

Question: are initialized pthread_mutex_t objects kernel persistent? -- concern is for Linux V 2.6 onward.

Motivation: If persistent: the objects resources will not be released with specific cleanup, pthread_mutex_destroy

In practical coding terms this means the mutex object will persist after the creating program exits or aborts without cleanup, unless pthread_mutex_destroy is called. I have code which is routinely removed by a nasty control program, that employs kill -9, SIGKILL, after trying kill -15 (SIGTERM). The design of the program is not going to change, it is vendor code. There is no way to alter its base behavior. Correctly cleaning up the code often takes longer than the control daemon likes, so 'zap' goes the process. This occurs frequently.

https://www.kernel.org/doc/Documentation/mutex-design.txt From Ingo Molnar

[ this is older material which says 'yes', spinlocks are a kernel mode object ]

'struct mutex' is the new mutex type, defined in include/linux/mutex.h and implemented in kernel/locking/mutex.c. It is a counter-based mutex with a spinlock and a wait-list. The counter has 3 states: 1 for "unlocked", 0 for "locked" and negative numbers (usually -1) for "locked, potential waiters queued".

http://man7.org/linux/man-pages/man2/execve.2.html has:

  • All threads other than the calling thread are destroyed during an execve(). Mutexes, condition variables, and other pthreads objects are not preserved.

So calling one of the exec(), family is not a way to determine persistence.

http://man7.org/linux/man-pages/man3/exit.3.html has nothing about mutexes one way or the other.

Can someone point me to definitive code or documentation one way or the other? I need to confront our vendor with something solid.

1
Ask yourself this: Could whatever problem you're imagining be used by a twelve-year-old to write a trivial DOS attack against a Linux server? If so, then the problem probably doesn't exist. - Kerrek SB
Yes, but the vendor is 11 years old. (humor). If what you say is true, then show me is all I ask. - jim mcnamara
The mutex documentation you're looking at is for kernel-internal use (between kernel components and modules). It has nothing to do with pthread mutexes. That may be the source of your confusion. - R.. GitHub STOP HELPING ICE
Thanks for the link +! @R.. - jim mcnamara

1 Answers

2
votes

Pthreads mutexes in Linux are not kernel objects. pthread_mutex_destroy does not make any system calls because there's no kernel resource to free. strace it and see for yourself.

The linked document by Ingo Molnar talks about mutexes that are internal to the Linux kernel, not about pthreads. They are totally different beasts.