| 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | #include <pthread.h> |
| 3 | #include <stdint.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | typedef int32_t OSSpinLock; |
| 7 | extern "C" void OSSpinLockLock(OSSpinLock *); |
| 8 | extern "C" void OSSpinLockUnlock(OSSpinLock *); |
| 9 | |
| 10 | int Global; |
| 11 | OSSpinLock lock; |
| 12 | |
| 13 | void *Thread(void *x) { |
| 14 | OSSpinLockLock(&lock); |
| 15 | Global++; |
| 16 | OSSpinLockUnlock(&lock); |
| 17 | return NULL; |
| 18 | } |
| 19 | |
| 20 | int main() { |
| 21 | fprintf(stderr, format: "Hello world.\n" ); |
| 22 | |
| 23 | pthread_t t[2]; |
| 24 | pthread_create(newthread: &t[0], NULL, start_routine: Thread, NULL); |
| 25 | pthread_create(newthread: &t[1], NULL, start_routine: Thread, NULL); |
| 26 | pthread_join(th: t[0], NULL); |
| 27 | pthread_join(th: t[1], NULL); |
| 28 | |
| 29 | fprintf(stderr, format: "Done.\n" ); |
| 30 | } |
| 31 | |
| 32 | // CHECK: Hello world. |
| 33 | // CHECK: Done. |
| 34 | // CHECK-NOT: WARNING: ThreadSanitizer |
| 35 | |