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 57D4A1F55B for ; Mon, 25 May 2020 08:14:58 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8828D383F873; Mon, 25 May 2020 08:14:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8828D383F873 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1590394497; bh=/pd5DsHD13B8t5twYtRLB6yin1H5ljijJbY+7Qv4n7Y=; h=To:Subject:In-Reply-To:Date:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=UZfnjgyM0hdGV2toWz8djEAq6U/WpJb2SfJ3X/HZy+J1JPuJ5mk76Qa+6ZYDb/ndH CuKroD0aVs7UhBgYgYRCKSTEVpyIdQOaLy39c6AodvPhqPZHzzqKNhg4mgTLDgLXpR k+o3/O6BGYLg5ygPYUJ1cB6dGMEKsn4pIGyjZkYo= Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 9FCE93858D35 for ; Mon, 25 May 2020 08:14:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9FCE93858D35 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-439-Rkq1npf5PyeJ3HLThjCYEg-1; Mon, 25 May 2020 04:14:52 -0400 X-MC-Unique: Rkq1npf5PyeJ3HLThjCYEg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 528C080183C; Mon, 25 May 2020 08:14:51 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-112-121.ams2.redhat.com [10.36.112.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2AB919D7B; Mon, 25 May 2020 08:14:49 +0000 (UTC) To: Rich Felker Subject: Re: [PATCH 2/2] manual: Document __libc_single_threaded In-Reply-To: <20200523160202.GG1079@brightrain.aerifal.cx> (Rich Felker's message of "Sat, 23 May 2020 12:02:03 -0400") Date: Mon, 25 May 2020 10:08:37 +0200 References: <20200522105458.GB29518@arm.com> <20200522150720.GR1079@brightrain.aerifal.cx> <20200522161413.GU1079@brightrain.aerifal.cx> <871rnb3nue.fsf@oldenburg2.str.redhat.com> <20200522172826.GW1079@brightrain.aerifal.cx> <87h7w727i4.fsf@oldenburg2.str.redhat.com> <20200522174932.GY1079@brightrain.aerifal.cx> <20200522192249.GC24880@arm.com> <20200522195326.GB1079@brightrain.aerifal.cx> <20200523064941.GD26190@port70.net> <20200523160202.GG1079@brightrain.aerifal.cx> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Message-ID: <87o8qczb0n.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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" * Rich Felker: >> this can allow earlier single threaded detection than only >> considering pthread_join: e.g. stdio, malloc etc may do a >> check and update the global after an acquire barrier, however >> the compiler must not cache globals across libc calls for this >> to work. > > It can't cache globals across non-pure functions whose definitions it > cant't see (and if it saw the definition it would know the global is > modified). Sorry about that, hit C-c C-c while I thought I was in a terminal. 8-/ For most standard C functions, it is well-known to which global variables (if any) they write. Of course, compilers exploit this fact. > malloc is something of a special case where clang treats it > not as a function but having "pure malloc semantics", but even then I > don't think it matters if it caches it; And of course malloc is the most common example of a standard function that has observable side effects beyond those specified in the standard: most implementations have a statistics interface. > at worst you see the old value of __libc_single_threaded (false) > rather than the new one (true) and that direction is safe. It's still a data race. The compiler can easily generate invalid code if it incorrectly assumes that __libc_single_threaded remains stable. I don't know if Clang will do this. But I think the C library implementation should be rather conservative here. Thanks, Florian