2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / tsan / fd_close_norace.C
blob4ed45bc717e491c0fb9a4808829955ee8867a770
1 #include <pthread.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
8 void *Thread1(void *x) {
9   int f = open("/dev/random", O_RDONLY);
10   close(f);
11   return NULL;
14 void *Thread2(void *x) {
15   sleep(1);
16   int f = open("/dev/random", O_RDONLY);
17   close(f);
18   return NULL;
21 int main() {
22   pthread_t t[2];
23   pthread_create(&t[0], NULL, Thread1, NULL);
24   pthread_create(&t[1], NULL, Thread2, NULL);
25   pthread_join(t[0], NULL);
26   pthread_join(t[1], NULL);
27   fprintf(stderr, "OK\n");
30 /* { dg-prune-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */