2 #include <mach/thread_act.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;
13 return g_running_count
;
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
26 running_func (void *input
) {
27 while (g_running_count
< 10) {
29 g_running_count
++; // Break here to show we can handle breakpoints
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