public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix race in background index-cache writing
Date: Thu, 30 Mar 2023 10:27:22 -0400	[thread overview]
Message-ID: <fdc6a2e2-c847-2bdb-8ae8-34319007801c@simark.ca> (raw)
In-Reply-To: <20230324215528.891455-1-tom@tromey.com>

On 3/24/23 17:55, Tom Tromey wrote:
> Tom de Vries pointed out a bug in the index-cache background writer --
> sometimes it will fail.  He also noted that it fails when the number
> of worker threads is set to zero.  These turn out to be the same
> problem -- the cache can't be written to until the per-BFD's
> "index_table" member is set.
> 
> This patch avoids the race by rearranging the code slightly, to ensure
> the cache cannot possibly be written before the member is set.

I've been seeing a lot of random failures of the index-cache tests
lately on my CI, so I presume this will help.

> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index c910be875a3..dbf323d0da0 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -5147,9 +5147,13 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
>    indexes.push_back (index_storage.release ());
>    indexes.shrink_to_fit ();
>  
> -  cooked_index *vec = new cooked_index (std::move (indexes), per_bfd);
> +  cooked_index *vec = new cooked_index (std::move (indexes));
>    per_bfd->index_table.reset (vec);
>  
> +  /* Cannot start writing the index entry until after the
> +     'index_table' member has been set.  */
> +  vec->start_writing_index (per_bfd);

An alternative I see would be to make cooked_index::cooked_index set the
per_bfd field itself (before starting the background task).  But if you
don't find it a clean solution for whatever reason, I think what you
have is fine.

Simon

  reply	other threads:[~2023-03-30 14:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 21:55 Tom Tromey
2023-03-30 14:27 ` Simon Marchi [this message]
2023-03-31 14:39   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fdc6a2e2-c847-2bdb-8ae8-34319007801c@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).