public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "siddhesh at redhat dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sources.redhat.com Subject: [Bug nptl/14652] New: Cancelling a pthread_cond_wait with PRIO_INHERIT mutex causes a deadlock Date: Mon, 01 Oct 2012 18:28:00 -0000 [thread overview] Message-ID: <bug-14652-131@http.sourceware.org/bugzilla/> (raw) http://sourceware.org/bugzilla/show_bug.cgi?id=14652 Bug #: 14652 Summary: Cancelling a pthread_cond_wait with PRIO_INHERIT mutex causes a deadlock Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: nptl AssignedTo: unassigned@sourceware.org ReportedBy: siddhesh@redhat.com CC: drepper.fsp@gmail.com Classification: Unclassified This is different from bug 14477, which is a deadlock due to an incorrect exception table. This problem is sometimes seen when a program with multiple waiters and signallers are cancelled. One of the waiters could get cancelled at a point after it has returned successfully from a futex_wait and before it disables async cancellation. Since a wait with PRIO_INHERIT mutex uses the FUTEX_WAIT_REQUEUE_PI futex operation, the futex syscall returns with the mutex locked. The cleanup handler subsequently tries to lock this already locked mutex, resulting in a deadlock. The following program demonstrates this on i386 as well as x86_64: #include <pthread.h> #include <stdio.h> #define NUM 5 #define ITERS 100000 pthread_mutex_t mutex; pthread_cond_t cond; void cleanup (void *u) { pthread_mutex_unlock (&mutex); } void * signaller (void *u) { int i; for (i = 0; i < ITERS / NUM; i++) { pthread_mutex_lock (&mutex); pthread_cond_signal (&cond); puts ("signalled"); fflush (stdout); pthread_mutex_unlock (&mutex); } } void * waiter (void *u) { int i; for (i = 0; i < ITERS / NUM; i++) { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 20; pthread_mutex_lock (&mutex); pthread_cleanup_push (cleanup, NULL); puts ("waiting..."); pthread_cond_timedwait (&cond, &mutex, &ts); puts ("waited"); fflush (stdout); pthread_mutex_unlock (&mutex); pthread_cleanup_pop (0); } } int main (void) { pthread_t w[NUM]; pthread_t s; pthread_mutexattr_t attr; int i; for (i = 0; i < ITERS; i++) { pthread_mutexattr_init (&attr); pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_INHERIT); pthread_cond_init (&cond, NULL); pthread_mutex_init (&mutex, &attr); for (i = 0; i < NUM; i++) pthread_create (&w[i], NULL, waiter, NULL); pthread_create (&s, NULL, signaller, NULL); for (i = 0; i < NUM; i++) { pthread_cancel (w[i]); pthread_join (w[i], NULL); } pthread_cancel (s); pthread_join (s, NULL); } return 0; } The program hangs after some iterations. I have a patch in the works that should fix this. -- 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.
next reply other threads:[~2012-10-01 18:28 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-01 18:28 siddhesh at redhat dot com [this message] 2012-10-01 18:28 ` [Bug nptl/14652] " siddhesh at redhat dot com 2012-10-01 19:54 ` bugdal at aerifal dot cx 2012-10-03 5:27 ` siddhesh at redhat dot com 2012-10-03 13:15 ` bugdal at aerifal dot cx 2012-10-10 7:28 ` siddhesh at redhat dot com 2014-06-25 6:46 ` fweimer at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-14652-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sources.redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).