From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 97FFE3858D33 for ; Wed, 2 Aug 2023 14:26:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97FFE3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AE2001F8A4; Wed, 2 Aug 2023 14:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690986380; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xQWssZ/17b0aIDm/paTpXW2VuTOuHOJtX7K9Ru8PqZo=; b=pfCLo6PAlgJe/SYvC/BwPsMUIetYE/+wZuQUTUr2IW0wnG1w9laSW3NYgIPVzVAIFzJFUG yP6p15/Q8SUf82ZvzSElVpYoiu/1GmhjpyiT6sg+3DE9+Niv7+Ihy82iIhbB9cOdDWZOIo o9Iw+kjNMclyAvuW8pZeuUFrLdKvO+E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690986380; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xQWssZ/17b0aIDm/paTpXW2VuTOuHOJtX7K9Ru8PqZo=; b=JZwaawEvcGcjYPFJxzn/O6me7cBMQACAKMBLl4lCMTFdvZJTGHi7cqL4hoOl0Eb9SyEAL3 nAS1MeCh9Ohn+4CQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8D25F13909; Wed, 2 Aug 2023 14:26:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1K9DIYxnymQyDQAAMHmgww (envelope-from ); Wed, 02 Aug 2023 14:26:20 +0000 Message-ID: Date: Wed, 2 Aug 2023 16:26:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] [gdb] Initialize main_thread_id earlier Content-Language: en-US To: Tom Tromey , Tom de Vries via Gdb-patches References: <20230728105945.13909-1-tdevries@suse.de> <20230728105945.13909-2-tdevries@suse.de> <877cqki3m0.fsf@tromey.com> From: Tom de Vries In-Reply-To: <877cqki3m0.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 7/28/23 15:10, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries via Gdb-patches writes: > > Tom> I wrote a patch using is_main_thread (), and found it returning false in the > Tom> main thread due to main_thread_id not being initialized yet. > > Tom> Initialization currently takes place in _initialize_run_on_main_thread, but > Tom> that's too late for earlier uses. > > Tom> Fix this by also initializing on first use. > > I wonder if it's enough to have: > > static std::thread::id main_thread_id = std::this_thread::get_id (); > In principle it's enough but it does expose us to the "Static Initialization Order Fiasco" [1], so I prefer this solution. > Tom> +#if CXX_STD_THREAD > Tom> +static void > Tom> +initialize_main_thread_id (void) > > "(void)" is only needed for C, you can just write "()" here. > Ack, I'll update it in my reply to Pedro. Thanks, - Tom [1] https://en.cppreference.com/w/cpp/language/siof