From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8614 Path: news.gmane.org!not-for-mail From: Bobby Bingham Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH v2 1/2] pthread: add missing memory barrier Date: Sun, 4 Oct 2015 14:55:29 -0500 Message-ID: <1443988530-23978-1-git-send-email-koorogi@koorogi.info> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1443988565 28365 80.91.229.3 (4 Oct 2015 19:56:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Oct 2015 19:56:05 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8626-gllmg-musl=m.gmane.org@lists.openwall.com Sun Oct 04 21:56:05 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 1ZipO8-0006Um-C5 for gllmg-musl@m.gmane.org; Sun, 04 Oct 2015 21:56:04 +0200 Original-Received: (qmail 27873 invoked by uid 550); 4 Oct 2015 19:55:59 -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 27752 invoked from network); 4 Oct 2015 19:55:50 -0000 X-Mailer: git-send-email 2.6.0 Xref: news.gmane.org gmane.linux.lib.musl.general:8614 Archived-At: POSIX requires pthread_join to synchronize memory on success. The futex wait inside __timedwait_cp cannot handle this because it's not called in all cases. Also, in the case of a spurious wake, tid can become zero between the wake and when the joining thread checks it. --- src/thread/pthread_join.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c index 966b4ab..694d377 100644 --- a/src/thread/pthread_join.c +++ b/src/thread/pthread_join.c @@ -13,6 +13,7 @@ int __pthread_join(pthread_t t, void **res) if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); while ((tmp = t->tid)) __timedwait_cp(&t->tid, tmp, 0, 0, 0); __pthread_setcancelstate(cs, 0); + a_barrier(); if (res) *res = t->result; if (t->map_base) __munmap(t->map_base, t->map_size); return 0; -- 2.6.0