1#include <stdio.h>
2#include <unistd.h>
3#include <pthread.h>
4
5volatile int g_thread_2_continuing = 0;
6
7void *
8thread_1_func (void *input)
9{
10    // Waiting to be released by the debugger.
11    while (!g_thread_2_continuing) // The debugger will change this value
12    {
13        usleep(1);
14    }
15
16    // Return
17    return NULL;  // Set third breakpoint here
18}
19
20void *
21thread_2_func (void *input)
22{
23    // Waiting to be released by the debugger.
24    int child_thread_continue = 0;
25    while (!child_thread_continue) // The debugger will change this value
26    {
27        usleep(1);  // Set second breakpoint here
28    }
29
30    // Release thread 1
31    g_thread_2_continuing = 1;
32
33    // Return
34    return NULL;
35}
36
37int main(int argc, char const *argv[])
38{
39    pthread_t thread_1;
40    pthread_t thread_2;
41
42    // Create a new thread
43    pthread_create (&thread_1, NULL, thread_1_func, NULL);
44
45    // Waiting to be attached by the debugger.
46    int main_thread_continue = 0;
47    while (!main_thread_continue) // The debugger will change this value
48    {
49        usleep(1);  // Set first breakpoint here
50    }
51
52    // Create another new thread
53    pthread_create (&thread_2, NULL, thread_2_func, NULL);
54
55    // Wait for the threads to finish.
56    pthread_join(thread_1, NULL);
57    pthread_join(thread_2, NULL);
58
59    printf("Exiting now\n");
60}
61