2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2012-12-08 02:30:40 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
void *Thread1(void *x) {
|
|
|
|
int f = open("/dev/random", O_RDONLY);
|
|
|
|
close(f);
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-08 02:30:40 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread2(void *x) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-08 02:30:40 +08:00
|
|
|
int f = open("/dev/random", O_RDONLY);
|
|
|
|
close(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2012-12-08 02:30:40 +08:00
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], NULL, Thread1, NULL);
|
|
|
|
pthread_create(&t[1], NULL, Thread2, NULL);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "OK\n");
|
2012-12-08 02:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: WARNING: ThreadSanitizer: data race
|
|
|
|
|
|
|
|
|