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
Thread(void * a)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
main()18 int main() {
19 pthread_t t1, t2;
20 global_variable = 0;
21 pthread_create(&t1, NULL, Thread, NULL);
22 pthread_create(&t2, NULL, Thread, NULL);
23 pthread_join(t1, NULL);
24 pthread_join(t2, NULL);
25 fprintf(stderr, "global_variable = %ld\n", global_variable);
26 }
27
28 // CHECK: global_variable = 2
29