X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;ds=sidebyside;f=c%2Fpthread_pause.c;h=90282a201f2ec96295c1f2e5461128a31bf6e055;hb=80c01dc929be0faeb1393872c3354c47be76df3d;hp=81620a5bad30145e450c49a00626bb4845752e76;hpb=d0c03bf12c2c930b628f8748ec26c25a38327066;p=mirrors%2FPrograms.git diff --git a/c/pthread_pause.c b/c/pthread_pause.c index 81620a5..90282a2 100644 --- a/c/pthread_pause.c +++ b/c/pthread_pause.c @@ -1,7 +1,7 @@ -//Filename: pause.c +//Filename: pthread_pause.c //Author: Tomas 'Harvie' Mudrunka 2021 -//Build: CFLAGS=-lpthread make pause; ./pause -//Test: valgrind --tool=helgrind ./pause +//Build: CFLAGS=-lpthread make pthread_pause; ./pthread_pause +//Test: valgrind --tool=helgrind ./pthread_pause //I've wrote this code as excercise to solve following stack overflow question: // https://stackoverflow.com/questions/9397068/how-to-pause-a-pthread-any-time-i-want/68119116#68119116 @@ -20,6 +20,8 @@ #define PTHREAD_XSIG_CONT (SIGRTMIN+1) #define PTHREAD_XSIGRTMIN (SIGRTMIN+2) //First unused RT signal +pthread_t main_thread; + void pthread_pause_handler(int signal) { //Do nothing when there are more signals pending (to cleanup the queue) sigset_t pending; @@ -94,11 +96,14 @@ void *thread_test() { pthread_pause_disable(); printf("Running!\n"); pthread_pause_enable(); + //pthread_pause(main_thread); + //pthread_unpause(main_thread); } } int main() { pthread_t t; + main_thread = pthread_self(); pthread_pause_enable(); //Will get inherited by all threads from now on //you need to call pthread_pause_enable (or disable) before creating threads, //otherwise first signal will kill whole process