public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: paul@linuxaudiosystems.com
Cc: Lee Revell <rlrevell@joe-job.com>, Andrew Morton <akpm@osdl.org>,
	Jamie Lokier <jamie@shareable.org>,
	linux-kernel@vger.kernel.org, mingo@elte.hu,
	Chris Morgan <cmorgan@alum.wpi.edu>,
	seto.hidetoshi@jp.fujitsu.com
Subject: Re: kernel bug: futex_wait hang
Date: Wed, 23 Mar 2005 08:43:12 -0500	[thread overview]
Message-ID: <20050323134312.GZ32746@devserv.devel.redhat.com> (raw)
In-Reply-To: <3726.71.100.26.22.1111583579.spork@webmail.linuxaudiosystems.com>

On Wed, Mar 23, 2005 at 05:12:59AM -0800, paul@linuxaudiosystems.com wrote:
> the hang occurs during an attempted thread cancel+join. we know from
> strace that one thread calls tgkill() on the other. the other thread is
> blocked in a poll call on a FIFO. after tgkill, the first thread enters a
> futex wait, apparently waiting for the thread ID of the cancelled thread
> to appear at some location (just a guess based on the info from strace).
> the wait never returns, and so the first thread ends up hung in
> pthread_join(). there are no user-defined mutexes or condvars involved.

If the thread that is to be cancelled is in async cancel state (it should
be when waiting in a poll and if cancellation is not disabled in that thread),
then pthread_cancel sends a SIGCANCEL signal to it via tgkill.
If tgkill succeeds (and thus pthread_cancel succeeds too) and you call
pthread_join on it, in the likely case the thread is still alive
pthread_join will FUTEX_WAIT on pd->tid, waiting until the thread dies.
NPTL threads are created with CLONE_CHILD_CLEARTID &self->tid, so this
futex will be FUTEX_WAKEd by mm_release in kernel whenever the thread is
exiting (or dying in some other way).

So, if pthread_join waits for the thread forever, the thread must be
around (otherwise pthread_join would not block on it; well, there could
be memory corruption in the program and anything would be possible then).
This would mean either that the poll has not been awaken by the SIGCANCEL
signal, or e.g. that one of the registered cleanup handlers (or C++
destructors) in the thread that is being cancelled get stuck for whatever
reason (deadlock, etc.).

	Jakub

  reply	other threads:[~2005-03-23 13:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-22  3:59 kernel bug: futex_wait hang Lee Revell
2005-03-22  4:20 ` Andrew Morton
2005-03-22  4:25   ` Lee Revell
2005-03-22  4:46     ` Jamie Lokier
2005-03-22  4:48   ` Jamie Lokier
2005-03-22  5:08     ` Andrew Morton
2005-03-22  5:30       ` Lee Revell
2005-03-22  6:34         ` Jakub Jelinek
2005-03-22 23:58           ` Lee Revell
2005-03-23 13:12             ` paul
2005-03-23 13:43               ` Jakub Jelinek [this message]
2005-03-22  5:15     ` Lee Revell
2005-03-22 15:30       ` Jamie Lokier
2005-03-22 23:18         ` Lee Revell

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=20050323134312.GZ32746@devserv.devel.redhat.com \
    --to=jakub@redhat.com \
    --cc=akpm@osdl.org \
    --cc=cmorgan@alum.wpi.edu \
    --cc=jamie@shareable.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paul@linuxaudiosystems.com \
    --cc=rlrevell@joe-job.com \
    --cc=seto.hidetoshi@jp.fujitsu.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: link
Be 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