From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60058.outbound.protection.outlook.com [40.107.6.58]) by sourceware.org (Postfix) with ESMTPS id 060FB386F432 for ; Fri, 22 May 2020 19:23:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 060FB386F432 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3M1JeSbUZeR1zWU2P8E1CPsk5n++tKlkPoLlY5KxSDs=; b=4M2Tv9YBQembwTa3sym4jtbe53jIv+BXzvxxots+HJMZZk9GATbCFxA2C5KE6GFo9NqBQt4rGKox6Z9K0Tg2ZQhSR4SOWhAh59unY+a7ZY+f8dfPths6JZXBV3USjb3vswboYeIHbE2mx37D0tJt810vxMh/Y0rK1xdMduPXeFQ= Received: from AM6PR02CA0036.eurprd02.prod.outlook.com (2603:10a6:20b:6e::49) by VE1PR08MB4848.eurprd08.prod.outlook.com (2603:10a6:802:a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Fri, 22 May 2020 19:22:59 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::e) by AM6PR02CA0036.outlook.office365.com (2603:10a6:20b:6e::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Fri, 22 May 2020 19:22:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Fri, 22 May 2020 19:22:59 +0000 Received: ("Tessian outbound cff7dd4de28a:v57"); Fri, 22 May 2020 19:22:58 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b5288e53d63becc7 X-CR-MTA-TID: 64aa7808 Received: from 30a92c00cf4e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 55536B74-8F4B-4B0C-868E-27F57EB1106B.1; Fri, 22 May 2020 19:22:53 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 30a92c00cf4e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 22 May 2020 19:22:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lGdh1lNYSUbTuhvaaA7fNiXEnJfhXIOUzkgWCB4ePoA1E5uDXKQ0K0UAZwjBH7/gJ3fAhwUXoAPpZpKhK2vPnpCDGZ2x2qsAMQwLNEEftiZFFU/LpioVYoQ9J5p8FzmktdVp+nf98vi0VyzvmDcAHBydMpiNXbFXqhJyCfrfqLfm+6SCm1HngTldT3PvLL+d+Ysl3oDHQ5SicUxaMRy4udVcXg/dqvs8O4JaZPAFWmn8LE/SioQL+cOsz0rUc9qWt8p00dtC7PNM7vttL+p1Ca9/TKZYw3bgnt5NwxHLbOaL/GXQIJlLFNsocOE1tGA1Zz+ejXaUy5JIzCHBXcMFJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3M1JeSbUZeR1zWU2P8E1CPsk5n++tKlkPoLlY5KxSDs=; b=Cb+aCQK2Px9c8I9Pykodjf0VL/ncyVOH4+2zAPx2lvX3OSN/yF9dkIku1sIE8ixTYr3/qD3PPSMcW2bX6sj0DWxN1tS4H340k4+1E8pOzB5D/lvPWVrjsd/XplztsSxQWXu42XbwLYvSvBa+DINqnKtQywMYxXXwNU34Bkktwjz34fOcXYDSAlM0EUs9EWGlEE7EvqlRMUUU+ATxuTG3VJ6+06u8PYLpd4o8ideww+vB1vKAu76c/i7sulYO2EIzNC5/dRDazoc7Fbqn0Airwy5WyZOj19GiO5bDI/aukIKXOaeVojRDP3MJX1ZEpFSdVzyy9wajpbubEBkMVT9zfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3M1JeSbUZeR1zWU2P8E1CPsk5n++tKlkPoLlY5KxSDs=; b=4M2Tv9YBQembwTa3sym4jtbe53jIv+BXzvxxots+HJMZZk9GATbCFxA2C5KE6GFo9NqBQt4rGKox6Z9K0Tg2ZQhSR4SOWhAh59unY+a7ZY+f8dfPths6JZXBV3USjb3vswboYeIHbE2mx37D0tJt810vxMh/Y0rK1xdMduPXeFQ= Authentication-Results-Original: libc.org; dkim=none (message not signed) header.d=none;libc.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB3926.eurprd08.prod.outlook.com (2603:10a6:20b:a7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23; Fri, 22 May 2020 19:22:51 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.3021.020; Fri, 22 May 2020 19:22:51 +0000 Date: Fri, 22 May 2020 20:22:50 +0100 From: Szabolcs Nagy To: Rich Felker Cc: Florian Weimer , libc-alpha@sourceware.org Subject: Re: [PATCH 2/2] manual: Document __libc_single_threaded Message-ID: <20200522192249.GC24880@arm.com> References: <87k115768f.fsf@oldenburg2.str.redhat.com> <20200522100146.GA29518@arm.com> <877dx45low.fsf@oldenburg2.str.redhat.com> <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> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200522174932.GY1079@brightrain.aerifal.cx> User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: LNXP123CA0022.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::34) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.55) by LNXP123CA0022.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.26 via Frontend Transport; Fri, 22 May 2020 19:22:51 +0000 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 85a5e364-8976-4b13-e49e-08d7fe8589d0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3926:|VE1PR08MB4848: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 04111BAC64 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Gytd4pfbZPCc58K/5tpG/4vkLdJOZ9miiN0bhy8frFttM6TCGtE/AePJFvID+BeXZlcYAampzRUpxlyFLprFG4HjNmlu+qy0vSki2dguhS+I38SNM150VeJ6gL5PpaONgrp/h/BNkrtDemlDQQcLu6NijGI4ZXUFqnbqxc6YZs1mP0Nop4yIWBlPFKjCJqFA5K4ADqlnJYdR0+F2WQLg1ceTGThoc6Z/OgZYXMZIOqPqYWoMw7ybraZs52Y2Mi2qKQgJk8PaJj297rKm+k4n9Jgd577pZt3QBaaeKVXt7kHLKR0FdgylA75ZqgRMtQGI X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(376002)(396003)(39860400002)(366004)(346002)(136003)(52116002)(7696005)(16526019)(8886007)(1076003)(5660300002)(36756003)(2616005)(956004)(186003)(4326008)(86362001)(2906002)(44832011)(6916009)(478600001)(8676002)(33656002)(316002)(55016002)(66476007)(66946007)(66556008)(8936002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mQH+tv2+X0gHtk5iivyPCxi1TIpZ3zq9ZLOnXjDFzJiz+VNzu3LTpkR7RfDmDnCwP1GSwX5f4rmTP785SNklSjkoQi1MQ70VSXvKdEan6OI62c2WCAJ6TQvVV7+ehVSh62wtx1k43x/vMPcDQqyFHiU9pFu89YUs7p5sai508Q3vcW1/nJHEY7w2+N+5PGJV+D3rICIw7U6Ch16d10PKGQxeBnYIr8BfxMzsHYd/+QFWNczMsZUws3Mz24G43D0SCI8sNrUh+DmAELLDhn5pnox3rTN9MD2leCKppCf1nfpb/S8TrYyfPp2zvHTI59sH3LH1zb1TzIH2bsHcJKtChGmI2x1W9ysNeAi3uSaLkZj2acxwUwb2Y/QvJvWyRVYZEXXpzlNLyG7uEnmtSR3Wibk0ckawcmRE+UZ8aT1YiaFxFAVcNEKXtfSqe1XDdw3orCEAtNLAQr1i2snhOgpBy51ps9Pvackv3rvMEzIRS1XlEY/+AV68raOtzi/SToFJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3926 Original-Authentication-Results: libc.org; dkim=none (message not signed) header.d=none;libc.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(346002)(136003)(376002)(396003)(39860400002)(46966005)(8936002)(8676002)(316002)(70206006)(2906002)(36756003)(956004)(44832011)(86362001)(33656002)(7696005)(55016002)(2616005)(36906005)(336012)(81166007)(8886007)(478600001)(6862004)(70586007)(356005)(186003)(5660300002)(4326008)(26005)(16526019)(82310400002)(82740400003)(1076003)(47076004); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: d78ded9c-bd35-4e21-ea8b-08d7fe85853a X-Forefront-PRVS: 04111BAC64 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j0iEij/lqzT3vRyqV36+pXpzMuI+eC/xq1ZqLiKeVR/zGbhUSMThuSl+HfzAYT/mHVERAxfLagDLc7I8YBPxfBhM5u7x1M9dVpwUFgqdmE5HbsCyoo2MhQq4OheduAok/mbHfT29JY4xGR4hbdK/MZanZQp+ZEmlHxbB9nQ0befWDlSpkv9JDndS7L2p8nIsIWP+sfBa76meqCA0rW/ZgdLbq8Z56vUO6saI9G7wNsr9ikLPoeUaudhkUNaPhKdLpkxfiV8Yd1ioq97q1yBFj4CynsKo/UMVW+2v6mxlOci7QJE6oB4w+BERUPCc92RF+jpz897C4Byf8MnuaiVoYkcaJ/bj0fihs+6YmpPKKAmxeAJj9J9XTnn75Wk+OhU4bsLWN+I2PhuD55o+1qIRvw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2020 19:22:59.1898 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 85a5e364-8976-4b13-e49e-08d7fe8589d0 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4848 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 22 May 2020 19:23:03 -0000 The 05/22/2020 13:49, Rich Felker wrote: > On Fri, May 22, 2020 at 07:40:19PM +0200, Florian Weimer via Libc-alpha wrote: > > * Rich Felker: > > > > >> Our discussion focused on the problem that observing a thread count of 1 > > >> in pthread_join does not necessarily mean that it is safe to assume at > > >> this point that the process is single-threaded, in glibc's > > >> implementation that uses a simple __nptl_nthreads counter decremented on > > >> the thread itself. This does not cause a low-level data race directly, > > >> but is potentially still incorrect (I'm not quite sure yet). > > > > > > pthread_join necessarily has an acquire barrier (this is a fundamental > > > requirement of the interface contract; join is acquiring the results > > > of the thread) so under some weak assumptions on unsynchronized memory > > > access (e.g. non-tearing, not seeing a value that wasn't stored > > > sometime between the last and next acquire barriers on the observer's > > > side) I think observing it from pthread_join is safe. > > > > Because of the meaning of the variable, it is *completely* safe if there > > are no detached threads, without any further assumptions. > > > > With detached threads an pthread_join observing a thread count of 1 (as > > decreased during thread exit), the validity of setting > > __libc_single_threaded depends on whether the kernel offers something > > that causes a memory write on thread exit. I know of at least two such > > I don't follow. Why do you care about the kernel entity exiting here? > You should only care about having a release barrier before the update > to the count, so that seeing the updated count guarantees seeing any > changes to memory made by the exiting detached thread. kernel entity matters if it writes user memory after the release barrier such that user code may observe it. (although that would likely break conformance or other properties too, not just single thread checks). another example is observing the detached thread via kernel apis like /proc/task: user code may expect to see a single os task when __libc_single_threaded is set. so i think the safest implementation never sets __libc_single_threaded back to true and second safest is one that only sets it back to true in pthread_join when there were no detached threads (or if using some os api it can verify that there really is only one kernel thread). if we want to allow kernel entities to be around but still tell the user when "as far as the libc is concerned there is only one thread", then i think __libc_single_threaded needs to be an extern call (that acts as a compiler barrier).