From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: libc-test: regression test for __timedwait ECANCELED omission
Date: Sat, 28 Feb 2015 21:59:54 -0500 [thread overview]
Message-ID: <20150301025954.GA8801@brightrain.aerifal.cx> (raw)
[-- Attachment #1: Type: text/plain, Size: 666 bytes --]
Attached is a regression test in the libc-test framework for the bug
fixed in commit 76ca7a5446a8aec2b671a401d5e1878c4704754e:
fix failure of internal futex __timedwait to report ECANCELED
as part of abstracting the futex wait, this function suppresses all
futex error values which callers should not see using a whitelist
approach. when the masked cancellation mode was added, the new
ECANCELED error was not whitelisted. this omission caused the new
pthread_cond_wait code using masked cancellation to exhibit a spurious
wake (rather than acting on cancellation) when the request arrived
after blocking on the cond var.
Rich
[-- Attachment #2: pthread_cond_wait-cancel_ignored.c --]
[-- Type: text/plain, Size: 1245 bytes --]
// commit 76ca7a5446a8aec2b671a401d5e1878c4704754e
// pthread_cond_wait should act on cancellation arriving after unlocking mutex
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include "test.h"
static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
static int waiting;
static void cleanup(void *p)
{
waiting = 0;
pthread_cond_signal(&cv);
pthread_mutex_unlock(&mx);
}
static void *waiter(void *p)
{
pthread_mutex_lock(&mx);
waiting = 1;
pthread_cond_signal(&cv);
pthread_cleanup_push(cleanup, 0);
while (waiting) pthread_cond_wait(&cv, &mx);
pthread_cleanup_pop(1);
return 0;
}
int main(void)
{
pthread_t td;
struct timespec ts;
void *rv;
pthread_mutex_lock(&mx);
pthread_create(&td, 0, waiter, 0);
while (!waiting) pthread_cond_wait(&cv, &mx);
pthread_cancel(td);
clock_gettime(CLOCK_REALTIME, &ts);
if ((ts.tv_nsec+=30000000) >= 1000000000) {
ts.tv_sec++;
ts.tv_nsec -= 1000000000;
}
while (waiting && !pthread_cond_timedwait(&cv, &mx, &ts));
waiting = 0;
pthread_cond_signal(&cv);
pthread_mutex_unlock(&mx);
pthread_join(td, &rv);
if (rv != PTHREAD_CANCELED)
t_error("pthread_cond_wait did not act on cancellation\n");
return t_status;
}
next reply other threads:[~2015-03-01 2:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-01 2:59 Rich Felker [this message]
2015-03-01 11:17 ` Szabolcs Nagy
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=20150301025954.GA8801@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).