| 1 | // RUN: %clang_tsan %s -o %t |
| 2 | // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' |
| 3 | |
| 4 | #include <os/lock.h> |
| 5 | #include <pthread.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | long global_variable; |
| 9 | os_unfair_lock lock = OS_UNFAIR_LOCK_INIT; |
| 10 | |
| 11 | void *Thread(void *a) { |
| 12 | os_unfair_lock_lock(&lock); |
| 13 | global_variable++; |
| 14 | os_unfair_lock_unlock(&lock); |
| 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | int main() { |
| 19 | pthread_t t1, t2; |
| 20 | global_variable = 0; |
| 21 | pthread_create(newthread: &t1, NULL, start_routine: Thread, NULL); |
| 22 | pthread_create(newthread: &t2, NULL, start_routine: Thread, NULL); |
| 23 | pthread_join(th: t1, NULL); |
| 24 | pthread_join(th: t2, NULL); |
| 25 | fprintf(stderr, format: "global_variable = %ld\n" , global_variable); |
| 26 | } |
| 27 | |
| 28 | // CHECK: global_variable = 2 |
| 29 | |