From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 72EBE1FA04 for ; Fri, 22 May 2020 11:08:27 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63C4B397CF00; Fri, 22 May 2020 11:08:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63C4B397CF00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1590145706; bh=pcPi+Ky8fY0Brzg+fvfHE4KjWdEsGMgu+eprTGPVJWQ=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=CHCB1QovVoCTuaEL3upnd+4VFo9ftWToyjnTCPOD4AwPsRY88/eikaQjMSOhIi1XB Ud/+cA/csE9eiLPW1gdG1dHS5gNkDfGj8S5S8Z1be8ykK+ctPuvCfeYMbzJVgJvq1w eZ2LgaQYPW2r9I3zil2Frr3W7e28htBSE9r9KpiA= Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 4160F397309B for ; Fri, 22 May 2020 11:08:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4160F397309B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-493-yCFZKM8yMVSuEIpMureC0A-1; Fri, 22 May 2020 07:08:18 -0400 X-MC-Unique: yCFZKM8yMVSuEIpMureC0A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84B1318B6427; Fri, 22 May 2020 11:08:17 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-112-155.ams2.redhat.com [10.36.112.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93FFC60E1C; Fri, 22 May 2020 11:08:16 +0000 (UTC) To: Szabolcs Nagy Subject: Re: [PATCH 2/2] manual: Document __libc_single_threaded References: <2c218c9ed9586ed5491f6fa08045d1e883b126c3.1589998207.git.fweimer@redhat.com> <724ecd59-d6e4-9f52-f425-8a4ff795114f@linaro.org> <20200521130927.GF14130@arm.com> <39687760-f8b1-4209-8798-ed8a16b87b57@linaro.org> <20200521133046.GH14130@arm.com> <87k115768f.fsf@oldenburg2.str.redhat.com> <20200522100146.GA29518@arm.com> <877dx45low.fsf@oldenburg2.str.redhat.com> <20200522105458.GB29518@arm.com> Date: Fri, 22 May 2020 13:08:15 +0200 In-Reply-To: <20200522105458.GB29518@arm.com> (Szabolcs Nagy's message of "Fri, 22 May 2020 11:54:58 +0100") Message-ID: <87y2pk4480.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Florian Weimer via Libc-alpha Reply-To: Florian Weimer Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" * Szabolcs Nagy: > The 05/22/2020 12:05, Florian Weimer wrote: >> * Szabolcs Nagy: >> >> > The 05/21/2020 15:44, Florian Weimer wrote: >> >> * Szabolcs Nagy: >> >> > what's wrong with pthread_join updating it? >> >> >> >> It's tricky do it correctly if there are two remaining threads, one of >> >> them the one being joined, the other one a detached thread. A >> >> straightforward implementation merely looking at __nptl_nthreads before >> >> returning from pthread_join would not perform the required >> >> synchronization on the detached thread exit. >> > >> > i'm trying to understand this, but don't see >> > what's wrong if the last thread is detached. >> >> Sorry, I meant three reamining threads in total, i.e., two more threads >> in addition to the one thread that keeps going after the other two >> exited, and may use __libc_single_threaded in the future. >> >> Clearer now? > > hm so a detached thread is concurrently exiting with > a pthread_join which sees a decremented __nptl_nthreads > but the detached thread has not actually exited yet. Correct. > i think glibc can issue a memory barrier syscall before > decrementing __nptl_nthreads in a detached thread, this > means if pthread_join observes __nptl_nthreads==1 > then user memory accesses in the detached thread are > synchronized with non-atomic memory accesses after > pthread_join returns. (i.e. __nptl_nthreads==1 should > mean at all times that as far as user code is concerned > the process is single threaded even if some detached > thread is still hanging around) This depends on the extent to which kernel actions after thread exit are visible to the last remaining threads. I think it would be safer to require that the stack must have been reclaimed. From a high-level perspective, we have a similar synchronization issue with stack reclamation, and it should be possible to reuse the same mechanism for that. > i think __libc_single_threaded should be possible to > update in pthread_join with the above change, in > which case we need not document that it stays false > forever, so we can change this in the future. Yes, I expect future such changes, which is why I mentioned saving the value of __libc_single_threaded for consistent execution. The other obvious case for optimization is fork, which is easier to implement: it is only necessary to detect that the libc in question is an outer libc. Thanks, Florian