llvm-project
31 строка · 683.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "test.h"3#include <sys/types.h>4#include <sys/stat.h>5#include <fcntl.h>6
7void *Thread1(void *x) {8int f = open("/dev/random", O_RDONLY);9close(f);10barrier_wait(&barrier);11return NULL;12}
13
14void *Thread2(void *x) {15barrier_wait(&barrier);16int f = open("/dev/random", O_RDONLY);17close(f);18return NULL;19}
20
21int main() {22barrier_init(&barrier, 2);23pthread_t t[2];24pthread_create(&t[0], NULL, Thread1, NULL);25pthread_create(&t[1], NULL, Thread2, NULL);26pthread_join(t[0], NULL);27pthread_join(t[1], NULL);28fprintf(stderr, "OK\n");29}
30
31// CHECK-NOT: WARNING: ThreadSanitizer: data race
32
33
34