2013-08-07 17:02:37 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
|
2013-01-17 21:18:40 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2013-11-28 17:06:55 +08:00
|
|
|
#include <unistd.h>
|
2014-04-04 17:52:41 +08:00
|
|
|
#include <errno.h>
|
2013-01-17 21:18:40 +08:00
|
|
|
|
|
|
|
int fd;
|
|
|
|
char buf;
|
|
|
|
|
|
|
|
void *Thread(void *x) {
|
2013-11-28 17:06:55 +08:00
|
|
|
sleep(1);
|
2013-01-17 21:18:40 +08:00
|
|
|
read(fd, &buf, 1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
fd = open("/dev/random", O_RDONLY);
|
2014-04-04 17:52:41 +08:00
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "failed to open /dev/random (%d)\n", errno);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-17 21:18:40 +08:00
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], NULL, Thread, NULL);
|
|
|
|
pthread_create(&t[1], NULL, Thread, NULL);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
|
|
|
close(fd);
|
2014-04-04 17:52:41 +08:00
|
|
|
fprintf(stderr, "DONE\n");
|
2013-01-17 21:18:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK: Write of size 1
|
|
|
|
// CHECK: #0 read
|
|
|
|
// CHECK: Previous write of size 1
|
|
|
|
// CHECK: #0 read
|
2014-04-04 17:52:41 +08:00
|
|
|
// CHECK: DONE
|
|
|
|
|