From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13793 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alexey Izbyshev Newsgroups: gmane.linux.lib.musl.general Subject: Re: Draft outline of thread-list design Date: Fri, 15 Feb 2019 01:54:09 +0300 Message-ID: References: <20190212182625.GA24199@brightrain.aerifal.cx> <66c00d56d718caa565209fd480158f98@ispras.ru> <20190214223224.GV23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="204795"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Roundcube Webmail/1.1.2 Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-13809-gllmg-musl=m.gmane.org@lists.openwall.com Thu Feb 14 23:54:23 2019 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.89) (envelope-from ) id 1guPtf-000rCF-Dx for gllmg-musl@m.gmane.org; Thu, 14 Feb 2019 23:54:23 +0100 Original-Received: (qmail 20224 invoked by uid 550); 14 Feb 2019 22:54:21 -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 20206 invoked from network); 14 Feb 2019 22:54:21 -0000 In-Reply-To: <20190214223224.GV23599@brightrain.aerifal.cx> X-Sender: izbyshev@ispras.ru Xref: news.gmane.org gmane.linux.lib.musl.general:13793 Archived-At: On 2019-02-15 01:32, Rich Felker wrote: > On Fri, Feb 15, 2019 at 12:16:39AM +0300, Alexey Izbyshev wrote: >> On 2019-02-12 21:26, Rich Felker wrote: >> >pthread_join: >> > >> >A joiner can no longer see the exit of the individual kernel thread >> >via the exit futex (detach_state), so after seeing it in an exiting >> >state, it must instead use the thread list to confirm completion of >> >exit. The obvious way to do this is by taking a lock on the list and >> >immediately releasing it, but the actual taking of the lock can be >> >elided by simply doing a futex wait on the lock owner being equal to >> >the tid (or an exit sequence number if we prefer that) of the exiting >> >thread. In the case of tid reuse collisions, at worse this reverts to >> >the cost of waiting for the lock to be released. >> > >> Since the kernel wakes only a single thread waiting on ctid address, >> wouldn't the joiner still need to do a futex wake to unblock other >> potential waiters even if it doesn't actually take the lock by >> changing *ctid? > > I'm not sure. If it's just a single wake rather than a broadcast then > yes, but only if it waited. If it observed the lock word != to the > exiting thread tid without performing a futex wait then it doesn't > have to do a futex wake. > Yes, it's a single wake: , . > >> In general, to my limited expertise, the design looks simple and >> clean. I'm not sure whether it's worth optimizing to reduce >> serialization pressure on pthread_create()/pthread_exit() because >> creating a large amount of short-lived threads doesn't look like a >> good idea anyway. > > Yes. One thing I did notice is that the window where pthread_create > has to hold a lock to prevent new dlopen from happening is a lot > larger than the window where the thread list needs to be locked, and > contains mmap/mprotect. I think we should add a new "DTLS lock" here > that's held for the whole time, with a protocol that if you need both > the DTLS lock and the thread list lock, you take them in that order > (dlopen would also need them both). This reduces the thread list lock > window to just the __clone call and list update. > Looks good. Alexey