1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t
3 // Data race randomly triggered.
4 // UNSUPPORTED: target={{.*netbsd.*}}
6 // Make sure TSan doesn't deadlock on a file stream lock at program shutdown.
7 // See https://github.com/google/sanitizers/issues/454
9 #define _WITH_GETLINE // to declare getline()
16 void *thread(void *unused
) {
21 // Forge a non-standard stream to make sure it's not closed.
22 FILE *stream
= fdopen(fd
[0], "r");
24 volatile int res
= getline(&line
, &size
, stream
);
33 pthread_attr_init(&a
);
34 pthread_attr_setdetachstate(&a
, PTHREAD_CREATE_DETACHED
);
35 pthread_create(&t
, &a
, thread
, NULL
);
36 pthread_attr_destroy(&a
);
37 fprintf(stderr
, "DONE\n");
39 // ThreadSanitizer used to hang here because of a deadlock on a file stream.