brintos

brintos / llvm-project-archived public Read only

0
0
Text · 733 B · 11c9828 Raw
27 lines · cpp
1// Simple stress test for of pthread_create. Increase arg to use as benchmark.2 3// RUN: %clangxx -O3 -pthread %s -o %t && %run %t 10004 5// Inconsistently fails on Android and can timeout on darwin platforms.6// UNSUPPORTED: android, darwin7 8#include <pthread.h>9#include <stdlib.h>10 11extern "C" const char *__asan_default_options() {12  // 32bit asan can allocate just a few FakeStacks.13  return sizeof(void *) < 8 ? "detect_stack_use_after_return=0" : "";14}15 16static void *null_func(void *args) { return nullptr; }17 18int main(int argc, char **argv) {19  int n = atoi(argv[1]);20  for (int i = 0; i < n; ++i) {21    pthread_t thread;22    if (pthread_create(&thread, 0, null_func, NULL) == 0)23      pthread_detach(thread);24  }25  return 0;26}27