[mlir][acc] Introduce MappableType interface (#122146)
[llvm-project.git] / lldb / test / API / linux / thread / create_during_instruction_step / main.cpp
blob3372cc5309c42c5a9ad731e74b30a7e5417bab73
1 // This file deliberately uses low level linux-specific API for thread creation because:
2 // - instruction-stepping over thread creation using higher-level functions was very slow
3 // - it was also unreliable due to single-stepping bugs unrelated to this test
4 // - some threading libraries do not create or destroy threads when we would expect them to
6 #include <sched.h>
8 #include <atomic>
9 #include <cstdio>
11 enum { STACK_SIZE = 0x2000 };
13 static uint8_t child_stack[STACK_SIZE];
15 pid_t child_tid;
17 std::atomic<bool> flag(false);
19 int thread_main(void *)
21 while (! flag) // Make sure the thread does not exit prematurely
24 return 0;
27 int main ()
29 int ret = clone(thread_main,
30 child_stack + STACK_SIZE/2, // Don't care whether the stack grows up or down,
31 // just point to the middle
32 CLONE_CHILD_CLEARTID | CLONE_FILES | CLONE_FS | CLONE_PARENT_SETTID |
33 CLONE_SIGHAND | CLONE_SYSVSEM | CLONE_THREAD | CLONE_VM,
34 nullptr, // thread_main argument
35 &child_tid);
37 if (ret == -1)
39 perror("clone");
40 return 1;
43 flag = true;
45 return 0;