c12de5a36bc614ff960c862601706593dc7e1b12
1 #define PTHREAD_FREEWHEEL
5 #include <pthread_extra.h>
11 //#define printf(...) (0)
13 pthread_t main_thread
;
15 void *thread_test(void *arg
) {
16 //Whole process dies if you kill thread immediately before it is pausable
17 //pthread_pause_enable();
19 pthread_nsleep(0, 1000*1000*300);
21 printf("Running%s!\n", (char *)arg
);
22 pthread_unpause_all();
23 pthread_pause(main_thread
);
24 pthread_unpause(main_thread
);
30 main_thread
= pthread_self();
33 pthread_pause_enable(); //Will get inherited by all threads from now on
34 //That way you can be sure it is pausable immediately
35 pthread_extra_create(&a
, NULL
, thread_test
, " A");
36 pthread_extra_create(&b
, NULL
, thread_test
, " B");
41 for(int32_t i = 1;i>0;i++) {
57 pthread_pause_disable();
58 pthread_pause_disable();
59 pthread_pause_disable();
60 printf("SWITCH A:\n");
61 pthread_pause_enable();
62 pthread_pause_enable();
63 pthread_pause_enable();
67 printf("SWITCH B:\n");
68 pthread_unpause_all();
73 //pthread_pause_disable();
75 printf("SWITCH A+B:\n");
76 pthread_unpause_all();
77 //pthread_pause_enable();
82 //pthread_pause_disable();
84 printf("SWITCH MAIN ONLY:\n");
85 //pthread_pause_enable();
89 printf("SWITCH MAIN A+B:\n");
90 pthread_unpause_all();
95 pthread_join(a
, NULL
);
96 pthread_join(b
, NULL
);
This page took 0.958592 seconds and 5 git commands to generate.