| 1 | // RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so |
| 2 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | // Extracted from: |
| 5 | // https://bugs.chromium.org/p/v8/issues/detail?id=4995 |
| 6 | |
| 7 | #include "test.h" |
| 8 | |
| 9 | void* 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(key: &keys_[i], destr_function: 0); |
| 14 | if (err) { |
| 15 | fprintf(stderr, format: "pthread_key_create failed with %d\n" , err); |
| 16 | exit(status: 1); |
| 17 | } |
| 18 | } |
| 19 | for (size_t i = 0; i < N; i++) |
| 20 | pthread_setspecific(key: keys_[i], pointer: (void*)(long)i); |
| 21 | for (size_t i = 0; i < N; i++) |
| 22 | pthread_key_delete(key: keys_[i]); |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | int main() { |
| 27 | for (int i = 0; i < 10; i++) { |
| 28 | pthread_t th; |
| 29 | pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0); |
| 30 | pthread_join(th: th, thread_return: 0); |
| 31 | } |
| 32 | pthread_t th[2]; |
| 33 | pthread_create(newthread: &th[0], attr: 0, start_routine: thr, arg: 0); |
| 34 | pthread_create(newthread: &th[1], attr: 0, start_routine: thr, arg: 0); |
| 35 | pthread_join(th: th[0], thread_return: 0); |
| 36 | pthread_join(th: th[1], thread_return: 0); |
| 37 | fprintf(stderr, format: "DONE\n" ); |
| 38 | // CHECK: DONE |
| 39 | } |
| 40 | |