From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7107 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: libc-test: regression test for __timedwait ECANCELED omission Date: Sat, 28 Feb 2015 21:59:54 -0500 Message-ID: <20150301025954.GA8801@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Dxnq1zWXvFF0Q93v" X-Trace: ger.gmane.org 1425178818 24886 80.91.229.3 (1 Mar 2015 03:00:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Mar 2015 03:00:18 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7120-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 01 04:00:13 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YRu72-0004kG-Ms for gllmg-musl@m.gmane.org; Sun, 01 Mar 2015 04:00:12 +0100 Original-Received: (qmail 26442 invoked by uid 550); 1 Mar 2015 03:00:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 26404 invoked from network); 1 Mar 2015 03:00:06 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7107 Archived-At: --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pthread_cond_wait-cancel_ignored.c" // commit 76ca7a5446a8aec2b671a401d5e1878c4704754e // pthread_cond_wait should act on cancellation arriving after unlocking mutex #include #include #include #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; } --Dxnq1zWXvFF0Q93v--