Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Feb 2001 07:56:39 -0500 (EST)
From:      Daniel Eischen <eischen@vigrid.com>
To:        "Paul D. Schmidt" <pds@uberhacker.org>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: known pthread bug?
Message-ID:  <Pine.SUN.3.91.1010205074310.10833A-100000@pcnet1.pcnet.com>
In-Reply-To: <20010204232301.C30977@uberhacker.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 4 Feb 2001, Paul D. Schmidt wrote:
> Are there currently any known bugs with pthread_mutex_init
> and pthread_cond_init returning 0, but pthread_cond_wait
> returning EINVAL nonetheless?

Yes, it's a known bug with the _application_ ;-)

pthread_cond_[timed]wait must be called with a mutex and that
must be the only mutex used with that condition variable.  For
instance:

	pthread_mutex_t	m1, m2;
	pthread_cond_t	cv;

	thread 1:
		pthread_mutex_lock(&m1);
		ret = pthread_cond_wait(&cv, &m1);
		pthread_mutex_unlock(&m1);

	thread 2:
		pthread_mutex_lock(&m2);
                ret = pthread_cond_wait(&cv, &m2);
                pthread_mutex_unlock(&m2);

can result in one of the threads returning EINVAL from
pthread_cond_wait if one thread is already waiting on the
condition variable when the other thread calls pthread_cond_wait().
There is no problem if only one thread is waiting on the
condition variable at any one time, but that still should
be avoided.

-- 
Dan Eischen


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.1010205074310.10833A-100000>