[LLVM][NVPTX] Add support for griddepcontrol instruction (#123511)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / Linux / reuse-threads.cpp
blobcb77e93e15f32c1827036442ee2bf6c6400d0d04
1 // Test that Thread objects are reused.
2 // RUN: %clangxx_hwasan -mllvm -hwasan-globals=0 -mllvm -hwasan-instrument-stack=0 %s -o %t && %env_hwasan_opts=verbose_threads=1 %run %t 2>&1 | FileCheck %s
4 #include <assert.h>
5 #include <fcntl.h>
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
11 #include <sanitizer/hwasan_interface.h>
13 pthread_barrier_t bar;
15 void *threadfn(void *) {
16 pthread_barrier_wait(&bar);
17 return nullptr;
20 void start_stop_threads() {
21 constexpr int N = 2;
22 pthread_t threads[N];
24 pthread_barrier_init(&bar, nullptr, N + 1);
25 for (auto &t : threads)
26 pthread_create(&t, nullptr, threadfn, nullptr);
28 pthread_barrier_wait(&bar);
30 for (auto &t : threads)
31 pthread_join(t, nullptr);
32 pthread_barrier_destroy(&bar);
35 int main() {
36 // Cut off initial threads.
37 // CHECK: === test start ===
38 fprintf(stderr, "=== test start ===\n");
40 // CHECK: Creating : T{{[0-9]+}} [[A:0x[0-9a-f]+]] stack:
41 // CHECK: Creating : T{{[0-9]+}} [[B:0x[0-9a-f]+]] stack:
42 start_stop_threads();
44 // CHECK-DAG: Creating : T{{[0-9]+}} [[A]] stack:
45 // CHECK-DAG: Creating : T{{[0-9]+}} [[B]] stack:
46 start_stop_threads();
48 // CHECK-DAG: Creating : T{{[0-9]+}} [[A]] stack:
49 // CHECK-DAG: Creating : T{{[0-9]+}} [[B]] stack:
50 start_stop_threads();
52 return 0;