]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/tsan/heap_race.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / tsan / heap_race.cc
CommitLineData
92a42be0
SL
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
1a4d82fc
JJ
3#include <pthread.h>
4#include <stdio.h>
5#include <stddef.h>
6
7void *Thread(void *a) {
8 ((int*)a)[0]++;
92a42be0 9 barrier_wait(&barrier);
1a4d82fc
JJ
10 return NULL;
11}
12
13int main() {
92a42be0 14 barrier_init(&barrier, 2);
1a4d82fc
JJ
15 int *p = new int(42);
16 pthread_t t;
17 pthread_create(&t, NULL, Thread, p);
92a42be0 18 barrier_wait(&barrier);
1a4d82fc
JJ
19 p[0]++;
20 pthread_join(t, NULL);
21 delete p;
22}
23
24// CHECK: WARNING: ThreadSanitizer: data race