简体   繁体   中英

Why if I have to set the pthread_sigmask before I wait to the specific signal

In one of threads I have to wait for specific real-time signal, but I don't understand why first I have to set the whole sigmask for thread before waiting for specific signal.

    sigset_t signals;
    siginfo_t info;

    sigfillset(&signals); 
    sigdelset(&signals, SIGRTMIN+1);

        //why do we need this?
    pthread_sigmask(SIG_SETMASK, &signals, NULL);

    sigemptyset(&signals);
    sigaddset(&signals, SIGRTMIN+1);
    sigwaitinfo(&signals, &info);
    printf("This is thread %d %d\n", pthread_self(), info.si_value.sival_int);


By looking to code it seems that developer want to suspend execution of thread until SIGRTMIN+1 has become pending for thread( sigwaitinfo(2) ). At the same time he don't want thread execution should be disturb by other signals(ie thread should not react to any signal except SIGRTMIN+1 ) so he masked other signals using below statement:

//why do we need this?
    pthread_sigmask(SIG_SETMASK, &signals, NULL);

The point to note here is even though all signals are masked except SIGRTMIN+1 using above statement, thread execution is always prone to SIGSTOP and SIGKILL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM