How to properly siglongjmp out of signal handler?

Posted by EpsilonVector on Stack Overflow See other posts from Stack Overflow or by EpsilonVector
Published on 2010-05-19T22:54:30Z Indexed on 2010/05/19 23:00 UTC
Read the original article Hit count: 350

Filed under:
|

Suppose I have the following code: In order to implement a context switch I activate ualarm and when it jumps to the handler it setjmp's the current context, and longjmps to the next, expecting to eventually return to the alarm handler and longjmped back into this context (the contexts are cycled through in a Round Robin). For this I need to keep SIGALRM unblocked in between alarm_handlers. I came up with the following code, which doesn't seem to work. What's wrong with it and what is the right way to do this?

void alarm_handler(){
    if(sigsetjmp(toc->threads[toc->RR_pointer].env, 0)){
        ualarm(200, 0);
        signal(SIGALRM, alarm_handler);
        return;
    }
    get_next_context_number(toc->RR_pointer); //is a macro
    for (j=0; j<10; j++) printf("ALARM HANDLER\n");
    siglongjmp(toc->threads[toc->RR_pointer].env, 1);
}

© Stack Overflow or respective owner

Related posts about longjmp

Related posts about linux