| 1 |
#include <dispatch/dispatch.h> |
| 2 |
#include <pthread.h> |
| 3 |
#include <stdio.h> |
| 4 |
#include <unistd.h> |
| 5 |
|
| 6 |
void do_work_level_5(void) { |
| 7 |
// Frame 0 will have these variables. |
| 8 |
int frame0_var = 100; |
| 9 |
const char *frame0_string = "frame_zero"; |
| 10 |
float frame0_float = 1.5f; |
| 11 |
|
| 12 |
// This is where we'll set the breakpoint. |
| 13 |
printf("Level 5 work executing\n"); // Break here. |
| 14 |
while (1) |
| 15 |
sleep(1); |
| 16 |
} |
| 17 |
|
| 18 |
void do_work_level_4(void) { |
| 19 |
// Frame 1 will have these variables. |
| 20 |
int frame1_var = 200; |
| 21 |
const char *frame1_string = "frame_one"; |
| 22 |
long frame1_long = 9876543210L; |
| 23 |
|
| 24 |
do_work_level_5(); |
| 25 |
} |
| 26 |
|
| 27 |
void do_work_level_3(void) { |
| 28 |
// Frame 2 will have these variables. |
| 29 |
int test_variable = 42; |
| 30 |
const char *test_string = "test_value"; |
| 31 |
double test_double = 3.14159; |
| 32 |
|
| 33 |
do_work_level_4(); |
| 34 |
} |
| 35 |
|
| 36 |
void do_work_level_2(void) { do_work_level_3(); } |
| 37 |
|
| 38 |
void do_work_level_1(void *context) { do_work_level_2(); } |
| 39 |
|
| 40 |
int main(int argc, const char *argv[]) { |
| 41 |
// Create a serial dispatch queue. |
| 42 |
dispatch_queue_t worker_queue = |
| 43 |
dispatch_queue_create("com.test.worker_queue", DISPATCH_QUEUE_SERIAL); |
| 44 |
dispatch_queue_t submitter_queue = |
| 45 |
dispatch_queue_create("com.test.submitter_queue", DISPATCH_QUEUE_SERIAL); |
| 46 |
|
| 47 |
// Submit work from one queue to another to create extended backtrace. |
| 48 |
dispatch_async_f(submitter_queue, &worker_queue, do_work_level_1); |
| 49 |
|
| 50 |
// Keep main thread alive. |
| 51 |
dispatch_main(); |
| 52 |
return 0; |
| 53 |
} |