Linux localhost 2.6.27.18 #1 SMP Thu Feb 19 22:58:17 MSK 2009 i686 i686 i386 GNU/Linux (glibc 2.7) valgrind-3.4.1 Problem: interprocess shared mutex reported as non-mutex (wrong). Test case: #include <pthread.h> int main() { int e; pthread_mutex_t _M_lock; pthread_mutexattr_t att; int ret = pthread_mutexattr_setpshared( &att, PTHREAD_PROCESS_SHARED ); pthread_mutex_init( &_M_lock, &att ); pthread_mutexattr_destroy( &att ); e = pthread_mutex_lock( &_M_lock ); pthread_mutex_unlock( &_M_lock ); pthread_mutex_destroy( &_M_lock ); return 0; } Valgrind options: valgrind --tool=drd --check-stack-var=yes --trace-children=yes --trace-cond=yes --trace-mutex=yes --trace-semaphore=yes obj/gcc/so_g/test Valgrind report: ==28953== drd, a thread error detector. ==28953== Copyright (C) 2006-2008, and GNU GPL'd, by Bart Van Assche. ==28953== Using LibVEX rev 1884, a library for dynamic binary translation. ==28953== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP. ==28953== Using valgrind-3.4.1, a dynamic binary instrumentation framework. ==28953== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al. ==28953== For more details, rerun with: -v ==28953== ==28953== [1/1] mutex_init invalid mutex 0xbeff6b24 ==28953== The object at address 0xbeff6b24 is not a mutex. ==28953== at 0x4027CF8: pthread_mutex_init (drd_pthread_intercepts.c:382) ==28953== by 0x804856C: main (test.c:10) ==28953== [1/1] mutex_trylock invalid mutex 0xbeff6b24 rc 0 owner 0 ==28953== ==28953== The object at address 0xbeff6b24 is not a mutex. ==28953== at 0x402642C: pthread_mutex_lock (drd_pthread_intercepts.c:414) ==28953== by 0x8048582: main (test.c:13) ==28953== mutex 0xbeff6b24 was first observed at: ==28953== at 0x402642C: pthread_mutex_lock (drd_pthread_intercepts.c:414) ==28953== by 0x8048582: main (test.c:13) ==28953== [1/1] post_mutex_lock invalid mutex 0xbeff6b24 rc 0 owner 0 ==28953== [1/1] mutex_unlock invalid mutex 0xbeff6b24 rc 1 ==28953== ==28953== The object at address 0xbeff6b24 is not a mutex. ==28953== at 0x4028794: pthread_mutex_unlock (drd_pthread_intercepts.c:463) ==28953== by 0x8048590: main (test.c:14) ==28953== mutex 0xbeff6b24 was first observed at: ==28953== at 0x402642C: pthread_mutex_lock (drd_pthread_intercepts.c:414) ==28953== by 0x8048582: main (test.c:13) ==28953== [1/1] mutex_destroy invalid mutex 0xbeff6b24 rc 1 owner 1 ==28953== ==28953== Destroying locked mutex: mutex 0xbeff6b24, recursion count 1, owner 1. ==28953== at 0x402853B: pthread_mutex_destroy (drd_pthread_intercepts.c:401) ==28953== by 0x804859B: main (test.c:15) ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 0 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 0 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== [1/1] mutex_trylock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] post_mutex_lock recursive mutex 0x401e260 rc 0 owner 1 ==28953== [1/1] mutex_unlock recursive mutex 0x401e260 rc 1 ==28953== ==28953== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
A bit correction: pthread_mutexattr_init( &att ); should be added in test before pthread_mutexattr_setpshared.
Created attachment 32097 [details] Proposed fix. Can you please try the attached patch ? The attached patch should apply fine to the Valgrind 3.4.1 source code. By the way, this patch has already been committed on the trunk and on the VALGRIND_3_4_BRANCH. The relevant commits are: 9398,9399,9400 and 9407 for the trunk, and 9408 for the 3.4 branch.
I'm check attached patch (against 3.4.1 release) and trunk (r9408). It work fine! Thanks.