Bug 30510 - Program calling exit() with active threads produces wrong output
Summary: Program calling exit() with active threads produces wrong output
Status: RESOLVED DUPLICATE of bug 15142
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-04 21:30 UTC by Paul Pluzhnikov
Modified: 2023-06-04 22:16 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2023-06-04 21:30:42 UTC
https://stackoverflow.com/a/76399940

I would expect the following program to never produce duplicate numbers:

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *func (void *p)
{
  size_t count = 0;
  while (1)
    printf ("%zu\n", ++count);

  return NULL;
}

int main (void)
{
  pthread_t tid;
  pthread_create (&tid, NULL, func, NULL);
  usleep (1000);
  return 0;
}


But running it against ToT produces:
1
2
...
260
261
262
263
264
265
266
267
267   <<<--- bug
268
269
270
270   <<<--- bug
271

This appears to stem from commit 64f01020838

commit 64f01020838a382d833254297f650d4a55933bde
Author: Ulrich Drepper <drepper@redhat.com>
Date:   Mon Feb 9 20:08:44 2004 +0000

    (_IO_cleanup): Do not use locking when flushing the buffers.  Some thread might be using a stream.


Not sure what the motivation was -- surely delaying exit a bit for sake of correctness would be more appropriate here?
Comment 2 Paul Pluzhnikov 2023-06-04 22:16:03 UTC
Seems like BZ 15142 is the closest to this. Closing as dup.

*** This bug has been marked as a duplicate of bug 15142 ***