From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id A0DA33858D37 for ; Wed, 2 Aug 2023 10:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0DA33858D37 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-out1.suse.de (Postfix) with ESMTPS id DA17921B18; Wed, 2 Aug 2023 10:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690972851; 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=QOt0TmNfjmWKz7tqWk2AWjXscl979x4uu8Eggdn1uQI=; b=mtwFVgQed8ZKjj403T4nkn2oyYuy8hb3HIDz0npdTO1FtdubX+FIMBcLiw5q4JPHXcca5N r289U7hLButGXaGAFv2A7BrdJlNVgVYivk7Z+qmekQeWvlr7Aisjvi5+aNJNN/e+pV5FCb X58WEH2jenTdyNGLgkIlZSDcHGwbKBw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690972851; 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=QOt0TmNfjmWKz7tqWk2AWjXscl979x4uu8Eggdn1uQI=; b=SXZSZvanPya6sr3v+jVNA/ceL+hdVhaHAPw6QzlLlWSJWk3VYrlVuDP7/8jijDxVLG1S27 5gcGcobp4oCy1+Aw== 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 C69C313919; Wed, 2 Aug 2023 10:40:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PkM7L7MyymRnDgAAMHmgww (envelope-from ); Wed, 02 Aug 2023 10:40:51 +0000 Message-ID: <13aec698-1c68-567d-5412-38b7dad24d65@suse.de> Date: Wed, 2 Aug 2023 12:40:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 1/3] [gdb/symtab] Fix data race in index_cache::enable Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20230728085645.3746-1-tdevries@suse.de> <20230728085645.3746-2-tdevries@suse.de> <43fcfbd2-115e-8458-8808-acdee98a2c83@polymtl.ca> From: Tom de Vries In-Reply-To: <43fcfbd2-115e-8458-8808-acdee98a2c83@polymtl.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 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 20:27, Simon Marchi wrote: Hi Simon, thanks for the review. >> The race is between: >> - the main thread setting index_cache::m_enabled >> (due to command "set index-cache enabled on") >> - a worker thread reading index_cache::m_enabled to determine whether an >> index-cache entry for $exec needs to be written >> (due to command "file $exec") >> >> Fix this by capturing the value of index_cache::m_enabled during the file >> command. > For completeness: in 30392, I initially suggested making m_enabled an > std::atomic. To which you responded: > > By making it a std::atomic, we make this non-determinism > defined behaviour, so tsan stops complaining, but we want > deterministic behaviour instead. > > I agree with that. Capturing the value at the time of the command makes > sense. > Ack, thanks for making that explicit. > One comment on the implementation. Do we really need to save an > index_cache_store_context object in cooked_index? Could we: > > - make get_store_context return it by value > - std::move it to the thread (or just copy it, if it's not expected to > be large) into the worker thread's closure (in > cooked_index::start_writing_index) > - pass it down by const-ref to whatever needs it I've implemented this approach in v2 ( https://sourceware.org/pipermail/gdb-patches/2023-August/201273.html ). I also realized that get_store_context is basically a constructor, so I've remodeled things in this way as well. Thanks, - Tom