brintos

brintos / llvm-project-archived public Read only

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