Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | #include <libkern/OSAtomic.h> |
| 3 | #include <pthread.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | int Global; |
| 7 | OSSpinLock lock; |
| 8 | |
| 9 | void *Thread(void *x) { |
| 10 | OSSpinLockLock(&lock); |
| 11 | Global++; |
| 12 | OSSpinLockUnlock(&lock); |
| 13 | return NULL; |
| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | fprintf(stderr, "Hello world.\n"); |
| 18 | |
| 19 | pthread_t t[2]; |
| 20 | pthread_create(&t[0], NULL, Thread, NULL); |
| 21 | pthread_create(&t[1], NULL, Thread, NULL); |
| 22 | pthread_join(t[0], NULL); |
| 23 | pthread_join(t[1], NULL); |
| 24 | |
| 25 | fprintf(stderr, "Done.\n"); |
| 26 | } |
| 27 | |
| 28 | // CHECK: Hello world. |
| 29 | // CHECK: Done. |
| 30 | // CHECK-NOT: WARNING: ThreadSanitizer |