Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] testsuite: Fix a race by me - watchthreads-reorder.exp
Date: Thu, 17 Dec 2009 20:27:00 -0000	[thread overview]
Message-ID: <m34onpgxcj.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20091217195026.GA21468@host0.dyn.jankratochvil.net> (Jan 	Kratochvil's message of "Thu, 17 Dec 2009 20:50:26 +0100")

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> there is a bug explainable by man pthread_cond_signal:
Jan> 	The [...] pthread_cond_signal() functions shall have no effect if
Jan> 	there are no threads currently blocked on cond.

Jan> +  i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex);
Jan> +  assert (i == 0);

pthread_cond_wait can also spuriously wake up.  The usual thing to do is
call it in a loop that checks some condition.  Then, have the signalling
thread set the condition before calling pthread_cond_signal.  Something
like:

while (thread1_tid == 0)
  pthread_cond_wait (...);

This is race-free as long as the signalling thread also acquires the
mutex associated with the condition.

Is there some reason not to do this in this test case?

Tom


  reply	other threads:[~2009-12-17 20:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-17 19:50 Jan Kratochvil
2009-12-17 20:27 ` Tom Tromey [this message]
2010-01-19 22:12   ` Jan Kratochvil
2010-01-20 21:01     ` Tom Tromey
2010-01-20 21:10       ` Jan Kratochvil

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=m34onpgxcj.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@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: 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