brintos

brintos / llvm-project-archived public Read only

0
0
Text · 975 B · 798caa4 Raw
40 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so2// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s3 4// Extracted from:5// https://bugs.chromium.org/p/v8/issues/detail?id=49956 7#include "test.h"8 9void* thr(void* arg) {10  const int N = 32;11  pthread_key_t keys_[N];12  for (size_t i = 0; i < N; ++i) {13    int err = pthread_key_create(&keys_[i], 0);14    if (err) {15      fprintf(stderr, "pthread_key_create failed with %d\n", err);16      exit(1);17    }18  }19  for (size_t i = 0; i < N; i++)20    pthread_setspecific(keys_[i], (void*)(long)i);21  for (size_t i = 0; i < N; i++)22    pthread_key_delete(keys_[i]);23  return 0;24}25 26int main() {27  for (int i = 0; i < 10; i++) {28    pthread_t th;29    pthread_create(&th, 0, thr, 0);30    pthread_join(th, 0);31  }32  pthread_t th[2];33  pthread_create(&th[0], 0, thr, 0);34  pthread_create(&th[1], 0, thr, 0);35  pthread_join(th[0], 0);36  pthread_join(th[1], 0);37  fprintf(stderr, "DONE\n");38  // CHECK: DONE39}40