[llvm] [DWARFLinkerParallel] Change more cases of compare_exchange_weak to compare_exchange_strong (PR #138692)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue May 6 13:47:57 PDT 2025


mstorsjo wrote:

> > > The remaining uses of compare_exchange_weak() in
> > > DWARFLinkerCompileUnit.h also seem very suspicious; if there would be a true concurrent write, leading to compare_exchange_weak() returning false, it seems like we would get stuck in an endless loop - but changing them to compare_exchange_strong() wouldn't make any difference with respect to that.
> > 
> > 
> > Can you have a look at these cases? (I haven't run into issues with them, but the code looks like it could lock up.)
> 
> yes, you are right those places look incorrect. Thank you for pointing to this.
> 
> Instead of
> 
> ```
>       auto InputData = Flags.load();
>       while (!Flags.compare_exchange_weak(InputData,
>                                           ((InputData & ~0x7) | Placement))) {
>       }
> ```
> 
> there should be something like
> 
> ```
>       do {
>         auto InputData = Flags.load();
>       while (!Flags.compare_exchange_weak(InputData,
>                                           ((InputData & ~0x7) | Placement)));
> ```
> 
> and loop should be added to:
> 
> ```
>       auto InputData = Flags.load();
>       if ((InputData & 0x7) == NotSet)
>         if (Flags.compare_exchange_weak(InputData, (InputData | Placement)))
>           return true;
> ```
> 
> Would you prefer me to do these changes or would you prefer to do these changes youself?

Yes, that looks correct to me. As you're more familiar with the overall intent here (I'm just trying to debug things that show up when running `ninja check` ;-) ) I'd prefer if you'd open such a PR, but I can review it!

https://github.com/llvm/llvm-project/pull/138692


More information about the llvm-commits mailing list