From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11599 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 4/8] determine the existence of private futexes at the first thread creation Date: Sat, 24 Jun 2017 18:23:38 -0400 Message-ID: <20170624222338.GX1627@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1498343034 27982 195.159.176.226 (24 Jun 2017 22:23:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 24 Jun 2017 22:23:54 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11612-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jun 25 00:23:48 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dOtT1-0006um-8O for gllmg-musl@m.gmane.org; Sun, 25 Jun 2017 00:23:47 +0200 Original-Received: (qmail 26270 invoked by uid 550); 24 Jun 2017 22:23:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 26249 invoked from network); 24 Jun 2017 22:23:49 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11599 Archived-At: On Tue, Jun 20, 2017 at 10:35:28PM +0200, Jens Gustedt wrote: > diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c > index ca5c6b90..26945022 100644 > --- a/src/thread/pthread_create.c > +++ b/src/thread/pthread_create.c > @@ -10,6 +10,8 @@ void *__mmap(void *, size_t, int, int, int, off_t); > int __munmap(void *, size_t); > int __mprotect(void *, size_t, int); > > +int __futex_private = 0; > + > static void dummy_0() > { > } > @@ -277,7 +279,13 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att > new->unblock_cancel = self->cancel; > new->CANARY = self->CANARY; > > - a_inc(&libc.threads_minus_1); > + if (!a_fetch_add(&libc.threads_minus_1, 1)) { > + // As long as we only have one thread, test if this supports > + // private futexes. > + __lock_t dummy = { 0 }; > + if (__syscall(SYS_futex, dummy.lc, FUTEX_WAKE|FUTEX_PRIVATE, 0) != -ENOSYS) > + __futex_private = FUTEX_PRIVATE; > + } > ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->tid); For future reference, this is also the wrong way to do "on first thread creation" -- it will trigger every time the number of threads changes from 1 to 2. There's already a block at the top of the function for first thread creation, that sets up stdio for multithreaded use and such; that would be the place to put this. I was also momentarily concerned about whether there are cases where a single-threaded process needs to be able to use the futex ops, but I think it probably doesn't matter except for the not-private case (pshared sync objects). Rich