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?
See bug 15142 and bug 14697. https://patchwork.sourceware.org/project/glibc/patch/mvmedyihcep.fsf@suse.de/
Seems like BZ 15142 is the closest to this. Closing as dup. *** This bug has been marked as a duplicate of bug 15142 ***