| 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | #include <pthread.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | struct P { |
| 7 | int x; |
| 8 | int y; |
| 9 | }; |
| 10 | |
| 11 | void *Thread(void *x) { |
| 12 | static P p = {.x: rand(), .y: rand()}; |
| 13 | if (p.x > RAND_MAX || p.y > RAND_MAX) |
| 14 | exit(status: 1); |
| 15 | return 0; |
| 16 | } |
| 17 | |
| 18 | int main() { |
| 19 | pthread_t t[2]; |
| 20 | pthread_create(newthread: &t[0], attr: 0, start_routine: Thread, arg: 0); |
| 21 | pthread_create(newthread: &t[1], attr: 0, start_routine: Thread, arg: 0); |
| 22 | pthread_join(th: t[0], thread_return: 0); |
| 23 | pthread_join(th: t[1], thread_return: 0); |
| 24 | fprintf(stderr, format: "PASS\n" ); |
| 25 | } |
| 26 | |
| 27 | // CHECK-NOT: WARNING: ThreadSanitizer: data race |
| 28 | |