Date: Fri, 8 Aug 2014 20:51:37 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: [PATCH] private futex support 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.