mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] private futex support
Date: Fri, 8 Aug 2014 20:51:37 -0400	[thread overview]
Message-ID: <20140809005137.GW1674@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140808113857.1839babf@vostro>

Just a quick explanation for some unexpected behavior you saw:

On Fri, Aug 08, 2014 at 11:38:57AM +0300, Timo Teras wrote:
> diff --git a/src/thread/pthread_cond_broadcast.c b/src/thread/pthread_cond_broadcast.c
> index 0901daf..4327a0e 100644
> --- a/src/thread/pthread_cond_broadcast.c
> +++ b/src/thread/pthread_cond_broadcast.c
> @@ -27,7 +27,7 @@ int pthread_cond_broadcast(pthread_cond_t *c)
>  
>  	/* Perform the futex requeue, waking one waiter unless we know
>  	 * that the calling thread holds the mutex. */
> -	__syscall(SYS_futex, &c->_c_seq, FUTEX_REQUEUE,
> +	__syscall(SYS_futex, &c->_c_seq, 128 | FUTEX_REQUEUE,
>  		!m->_m_type || (m->_m_lock&INT_MAX)!=__pthread_self()->tid,
>  		INT_MAX, &m->_m_lock);
>  
> diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c
> index 99d62cc..73c1781 100644
> --- a/src/thread/pthread_cond_timedwait.c
> +++ b/src/thread/pthread_cond_timedwait.c
> @@ -64,7 +64,7 @@ int pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict
>  
>  	pthread_mutex_unlock(m);
>  
> -	do e = __timedwait(&c->_c_seq, seq, c->_c_clock, ts, cleanup, &cm, 0);
> +	do e = __timedwait(&c->_c_seq, seq, c->_c_clock, ts, cleanup, &cm, 1);
>  	while (c->_c_seq == seq && (!e || e==EINTR));
>  	if (e == EINTR) e = 0;
>  
> It seems that things worked even without these changes, but everything
> was a lot slower. Not sure why. But the code sounds buggy anyway,

Both the wait and wake (requeue) operations for this futex were
wrongly shared rather than private, so since they still matched it
makes sense that it didn't fail. The requeue was wrongly requeuing as
shared on a mutex that would only receive a wake as private, but since
there was only one waiter and the requeue requested one wake, I guess
no requeue ever happened.

Rich


  reply	other threads:[~2014-08-09  0:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 18:48 Rich Felker
2014-08-08  8:38 ` Timo Teras
2014-08-09  0:51   ` Rich Felker [this message]
2014-08-09  1:50   ` Rich Felker

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=20140809005137.GW1674@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).