1#include <errno.h>
2#include <pthread.h>
3#include <stdio.h>
4#include <unistd.h>
5
6static unsigned int g_timeout = 100000;
7
8extern int usleep(unsigned int);
9
10int function_to_call() {
11
12 errno = 0;
13 while (1) {
14 int result = usleep(g_timeout);
15 if (errno != EINTR)
16 break;
17 }
18
19 pthread_exit(retval: (void *)10);
20
21 return 20; // Prevent warning
22}
23
24void *exiting_thread_func(void *unused) {
25 function_to_call(); // Break here and cause the thread to exit
26 return NULL;
27}
28
29int main() {
30 char *exit_ptr;
31 pthread_t exiting_thread;
32
33 pthread_create(newthread: &exiting_thread, NULL, start_routine: exiting_thread_func, NULL);
34
35 pthread_join(th: exiting_thread, thread_return: &exit_ptr);
36 int ret_val = (int)exit_ptr;
37 usleep(g_timeout * 4); // Make sure in the "run all threads" case
38 // that we don't run past our breakpoint.
39 return ret_val; // Break here to make sure the thread exited.
40}
41

source code of lldb/test/API/functionalities/thread/exit_during_expression/main.c