linux-mips
[Top] [All Lists]

Re: A linuxthreads bug on mips?

To: "H . J . Lu" <hjl@lucon.org>
Subject: Re: A linuxthreads bug on mips?
From: Ulrich Drepper <drepper@redhat.com>
Date: 29 Jan 2002 00:54:41 -0800
Cc: GNU C Library <libc-alpha@sources.redhat.com>, linux-mips@oss.sgi.com
In-reply-to: <20020125234542.A31028@lucon.org>
References: <20020125234542.A31028@lucon.org>
Reply-to: drepper@redhat.com (Ulrich Drepper)
Sender: owner-linux-mips@oss.sgi.com
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (asparagus)
"H . J . Lu" <hjl@lucon.org> writes:

> Here is a modified ex2.c which only uses one conditional variable. It
> works fine on x86. But it leads to dead lock on mips where both
> producer and consumer are suspended. Is this testcase correct?

Only if you assume fair scheduling which is not necessarily the case.
Assume the put() function has to stop because the buffer is full.  The
get() function now reads.  It can read everything.  Calling
pthread_cond_signal() does not mean that the put() function gets
running.  Instead get() keeps running and exhausts the input buffer
and then gets in the

    while (b->writepos == b->readpos)
    {
      pthread_cond_wait (&b->notempty, &b->lock);
    }
 
loop where it can wake up immediately.  put() never is required to be
runnable.

Therefore your revised code is not acceptable although it probably
will almost always work.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

<Prev in Thread] Current Thread [Next in Thread>