public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/14076] New: PTHREAD_MUTEX_LOCK() in multiple threads RETURNING EOWNERDEAD
@ 2012-05-08  3:40 zhenzhong.duan at oracle dot com
  2012-05-08 13:50 ` [Bug nptl/14076] " bugdal at aerifal dot cx
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: zhenzhong.duan at oracle dot com @ 2012-05-08  3:40 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14076

             Bug #: 14076
           Summary: PTHREAD_MUTEX_LOCK() in multiple threads RETURNING
                    EOWNERDEAD
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: critical
          Priority: P2
         Component: nptl
        AssignedTo: unassigned@sourceware.org
        ReportedBy: zhenzhong.duan@oracle.com
                CC: drepper.fsp@gmail.com
    Classification: Unclassified


Created attachment 6400
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6400
code to test concurrency of thread calling pthread_mutex_lock

When a thread that hold mutex lock dead, multiple other threads that call
PTHREAD_MUTEX_LOCK() return EOWNERDEAD

From the POSIX docs

(http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_03)

The implementation shall behave as if at all times there is at most one owner
of any mutex.

A thread that becomes the owner of a mutex is said to have "acquired" the
mutex and the mutex is said to have become "locked''; when a thread gives up
ownership of a mutex it is said to have "released" the mutex and the mutex is
said to have become "unlocked".

Robust mutexes provide a means to enable the implementation to notify other
threads in the event of a process terminating while one of its threads holds
a mutex lock. The next thread that acquires the mutex is notified about the
termination by the return value [EOWNERDEAD] from the locking function. The
notified thread can then attempt to recover the state protected by the mutex,
and if successful mark the state protected by the mutex as consistent by a
call to pthread_mutex_consistent(). If the notified thread is unable to
recover the state, it can declare the state as not recoverable by a call to
pthread_mutex_unlock() without a prior call to pthread_mutex_consistent().

To me, this implies that the thread that receives the EOWNERDEAD status has
also “acquired” the mutex (i.e. has locked the mutex). Given this, only one
thread should be able to receive the EOWNERDEAD notification (otherwise,
multiple threads have “acquired” the mutex – which contradicts the POSIX
descriptions above).

Attached test code futexCase1_r1.cpp,
$ g++ -Wall -O3 -m32 -march=i686 futexCase1-r1.cpp -o futexCase1_r1 –lpthread
$ futexCase1_r1
27658: created mutex: 0xf7fdc000
......
27944: pthread_mutex_consistent_np failed: 0xf7fdc000 22 Invalid argument
28032: pthread_mutex_consistent_np failed: 0xf7fdc000 22 Invalid argument
28072: pthread_mutex_consistent_np failed: 0xf7fdc000 22 Invalid argument
27658: Done! lock concurrency: 0, max: 5 

Based on the man-pages, pthread_mutex_consistent_np() should only fail if the
mutex supplied is invalid (not initialized, etc.), or if the mutex is NOT in
an inconsistent state.  Given this, my speculation for the failure is that
multiple pthread_mutex_lock() calls are being allowed to simultaneously
return (incorrectly) with the EOWNERDEAD status, causing some of the
subsequent pthread_mutex_consistent_np() calls to fail because the mutex
state has already been made consistent.

Lastly, from looking at the resulting max-concurrency (5 in this case) we see
that the code protected by the mutex is NOT being single threaded by the
mutex as expected.

We originally reproduce this bug in 2.5-81.el5_8.2. I also tried with fedora16
newest, still reproduce.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-06-13 14:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-08  3:40 [Bug nptl/14076] New: PTHREAD_MUTEX_LOCK() in multiple threads RETURNING EOWNERDEAD zhenzhong.duan at oracle dot com
2012-05-08 13:50 ` [Bug nptl/14076] " bugdal at aerifal dot cx
2012-06-08  6:02 ` zhenzhong.duan at oracle dot com
2012-06-08  6:05 ` zhenzhong.duan at oracle dot com
2012-10-04 14:45 ` siddhesh at redhat dot com
2012-10-04 14:46 ` siddhesh at redhat dot com
2012-10-05  6:21 ` siddhesh at redhat dot com
2012-10-09  6:14 ` zhenzhong.duan at oracle dot com
2012-10-11 15:05 ` siddhesh at redhat dot com
2014-02-16 18:23 ` jackie.rosen at hushmail dot com
2014-05-28 19:42 ` schwab at sourceware dot org
2014-06-13 14:06 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).