public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Vitaly Buka <vitalybuka@google.com>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: libc-alpha@sourceware.org,
	 Adhemerval Zanella <adhemerval.zanella@linaro.org>
Subject: Re: commit 16adc58e73f3 (stdlib: Fix data race in __run_exit_handlers [BZ #27749])
Date: Sun, 12 Feb 2023 17:54:29 -0800	[thread overview]
Message-ID: <CAPjTjwswS5a3p7z4O4eBT+-ERsvY4LLuMogRL2-6j9L0Z+G=MQ@mail.gmail.com> (raw)
In-Reply-To: <0a4a8828-ed9a-66d4-f65c-f2f386768bdb@prevas.dk>

[-- Attachment #1: Type: text/plain, Size: 1637 bytes --]

Not sure how this happened, but it was not on my patch
https://sourceware.org/pipermail/libc-alpha/2021-April/125470.html

On Sun, 12 Feb 2023 at 15:44, Rasmus Villemoes <rasmus.villemoes@prevas.dk>
wrote:

> I think the commit in $subject is broken. I was browsing through the
> atexit handling code and stumbled on something which is always a code
> smell, namely the pattern
>
>   if (whatever)
>     continue;
>
> at the end of a loop.
>
> And indeed, since we no longer jump back to the outer loop and refetch
> the list head, one can observe a change in behavior. This program:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> void h(void)
> {
>         printf("third: %s()\n", __func__);
> }
> void j(void)
> {
>         printf("second: %s()\n", __func__);
> }
>
> void g(void)
> {
>         printf("first: %s()\n", __func__);
>         atexit(h);
>         atexit(j);
> }
> void f(void) {
>         static int c;
>         printf("%s: %d\n", __func__, ++c);
> }
>
> int main(int argc, char *argv[])
> {
>         int i;
>
>         /*
>          * Stuff the "struct exit_function_list" with dummy callbacks;
>          * 30 may need to be adjusted depending on how many atexit()
>          * registrations libc itself does.
>          */
>         for (i = 0; i < 30; ++i)
>                 atexit(f);
>
>         /* Register one more, to fill the last slot in struct
> exit_function_list. */
>         atexit(g);
>
>         return 0;
> }
>
> used to print
>
> first: g()
> second: j()
> third: h()
> f: 1
> ...
> f: 30
>
> but now it instead prints
>
> first: g()
> third: h()
> f: 1
> ...
> f: 30
> second: j()
>
>
> Rasmus
>

  reply	other threads:[~2023-02-13  1:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-12 23:43 Rasmus Villemoes
2023-02-13  1:54 ` Vitaly Buka [this message]
2023-02-13  5:57   ` [PATCH] stdlib: Undo post review change to 16adc58e73f3 [BZ #27749] Vitaly Buka
2023-02-13  6:01 ` Vitaly Buka
2023-02-13 16:27   ` Adhemerval Zanella Netto
2023-02-18 20:53     ` Vitaly Buka
2023-02-20 12:20       ` Adhemerval Zanella Netto

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='CAPjTjwswS5a3p7z4O4eBT+-ERsvY4LLuMogRL2-6j9L0Z+G=MQ@mail.gmail.com' \
    --to=vitalybuka@google.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=rasmus.villemoes@prevas.dk \
    /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).