X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=c%2Fpthread_extra%2Ftest_pause.c;h=439c6d8d22de9da53d1807b2b42222e835cb03b3;hb=3109d0d18e330e166a45042a2d363ec1b285c493;hp=467328940c87c786f61b024436de2506a4fa8dc6;hpb=24286ba9a7ae3a8c6f5eefe9455e18bd758e742b;p=mirrors%2FPrograms.git diff --git a/c/pthread_extra/test_pause.c b/c/pthread_extra/test_pause.c index 4673289..439c6d8 100644 --- a/c/pthread_extra/test_pause.c +++ b/c/pthread_extra/test_pause.c @@ -6,23 +6,31 @@ #include #include +pthread_t main_thread; + void *thread_test(void *arg) { //Whole process dies if you kill thread immediately before it is pausable //pthread_pause_enable(); while(1) { - usleep(1000*300); + pthread_nsleep(0, 1000*1000*300); + //pthread_pause_all(); + pthread_pause(main_thread); printf("Running%s!\n", (char *)arg); + //pthread_unpause_all(); + pthread_unpause(main_thread); } } int main() { + main_thread = pthread_self(); + pthread_t a, b; pthread_pause_enable(); //Will get inherited by all threads from now on //That way you can be sure it is pausable immediately - pthread_create(&a, NULL, thread_test, " A"); - pthread_create(&b, NULL, thread_test, " B"); - //sleep(1); + pthread_extra_create(&a, NULL, thread_test, " A"); + pthread_extra_create(&b, NULL, thread_test, " B"); + //pthread_sleep(1); //printf("OK\n"); /* @@ -43,17 +51,24 @@ int main() { pthread_pause(b); pthread_unpause(a); printf("SWITCH A:\n"); - sleep(2); + pthread_sleep(2); printf("SWITCH B:\n"); pthread_pause(a); pthread_unpause(b); - sleep(2); + pthread_sleep(2); printf("SWITCH A+B:\n"); pthread_unpause(a); pthread_unpause(b); - sleep(1); + pthread_sleep(1); + + printf("SWITCH MAIN ONLY:\n"); + pthread_pause_all(); + pthread_sleep(1); + printf("SWITCH MAIN A+B:\n"); + pthread_unpause_all(); + pthread_sleep(1); } pthread_join(a, NULL);