* libc-test: regression test for __timedwait ECANCELED omission
@ 2015-03-01 2:59 Rich Felker
2015-03-01 11:17 ` Szabolcs Nagy
0 siblings, 1 reply; 2+ messages in thread
From: Rich Felker @ 2015-03-01 2:59 UTC (permalink / raw)
To: musl
[-- 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;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: libc-test: regression test for __timedwait ECANCELED omission
2015-03-01 2:59 libc-test: regression test for __timedwait ECANCELED omission Rich Felker
@ 2015-03-01 11:17 ` Szabolcs Nagy
0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2015-03-01 11:17 UTC (permalink / raw)
To: musl
* Rich Felker <dalias@libc.org> [2015-02-28 21:59:54 -0500]:
> Attached is a regression test in the libc-test framework for the bug
> fixed in commit 76ca7a5446a8aec2b671a401d5e1878c4704754e:
>
committed this and the other two getpwnam_r tests
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-01 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-01 2:59 libc-test: regression test for __timedwait ECANCELED omission Rich Felker
2015-03-01 11:17 ` Szabolcs Nagy
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).