Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / macosx / thread_suspend / main.c
blob03da7a71505c7a3d95a7887c57e434e598a03697
1 #include <pthread.h>
2 #include <mach/thread_act.h>
3 #include <unistd.h>
5 pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER;
6 pthread_mutex_t signal_mutex = PTHREAD_MUTEX_INITIALIZER;
7 pthread_cond_t signal_cond = PTHREAD_COND_INITIALIZER;
9 int g_running_count = 0;
11 int
12 function_to_call() {
13 return g_running_count;
16 void *
17 suspend_func (void *unused) {
18 pthread_setname_np("Look for me");
19 pthread_cond_signal(&signal_cond);
20 pthread_mutex_lock(&suspend_mutex);
22 return NULL; // We allowed the suspend thread to run
25 void *
26 running_func (void *input) {
27 while (g_running_count < 10) {
28 usleep (100);
29 g_running_count++; // Break here to show we can handle breakpoints
31 return NULL;
34 int
35 main()
37 pthread_t suspend_thread; // Stop here to get things going
39 pthread_mutex_lock(&suspend_mutex);
40 pthread_mutex_lock(&signal_mutex);
41 pthread_create(&suspend_thread, NULL, suspend_func, NULL);
43 pthread_cond_wait(&signal_cond, &signal_mutex);
45 mach_port_t th_port = pthread_mach_thread_np(suspend_thread);
46 thread_suspend(th_port);
48 pthread_mutex_unlock(&suspend_mutex);
50 pthread_t running_thread;
51 pthread_create(&running_thread, NULL, running_func, NULL);
53 pthread_join(running_thread, NULL);
54 thread_resume(th_port); // Break here after thread_join
56 pthread_join(suspend_thread, NULL);
57 return 0; // Break here to make sure the thread exited normally