public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* commit 16adc58e73f3 (stdlib: Fix data race in __run_exit_handlers [BZ #27749])
@ 2023-02-12 23:43 Rasmus Villemoes
  2023-02-13  1:54 ` Vitaly Buka
  2023-02-13  6:01 ` Vitaly Buka
  0 siblings, 2 replies; 7+ messages in thread
From: Rasmus Villemoes @ 2023-02-12 23:43 UTC (permalink / raw)
  To: libc-alpha; +Cc: Vitaly Buka, Adhemerval Zanella

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-20 12:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-12 23:43 commit 16adc58e73f3 (stdlib: Fix data race in __run_exit_handlers [BZ #27749]) Rasmus Villemoes
2023-02-13  1:54 ` Vitaly Buka
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

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).