38 lines · cpp
1// Check that concurent GetCurrentThread does not crash.2// RUN: %clangxx_lsan -O3 -pthread %s -o %t && %run %t 1003 4// REQUIRES: lsan-standalone5 6// For unknown reason linker can't resolve GetCurrentThread on7// https://ci.chromium.org/p/chromium/builders/try/mac_upload_clang.8// UNSUPPORTED: darwin9 10#include <pthread.h>11#include <stdlib.h>12#include <vector>13 14#include <sanitizer/common_interface_defs.h>15 16namespace __lsan {17class ThreadContextLsanBase *GetCurrentThread();18}19 20void *try_to_crash(void *args) {21 for (int i = 0; i < 100000; ++i)22 __lsan::GetCurrentThread();23 return nullptr;24}25 26int main(int argc, char **argv) {27 std::vector<pthread_t> threads;28 for (int i = 0; i < atoi(argv[1]); ++i) {29 threads.resize(10);30 for (auto &thread : threads)31 pthread_create(&thread, 0, try_to_crash, NULL);32 33 for (auto &thread : threads)34 pthread_join(thread, nullptr);35 }36 return 0;37}38