Operating System - HP-UX
1752297 Members
4625 Online
108786 Solutions
New Discussion

Re: Why SIGALRM can't happen in thread on HP-UX?

 
rchaurasiya
Occasional Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

Hi yang,

 

You havent indicated your code donig SIG_UNBLOCK in new thread as Dennis said. Can you confirm that?

Also, pthread_kill() worked because you are forcing signal to be sent to new thread, while alarm will make it to post on process, where kernel will direct it to an appropriate thread.

 

Thanks, Ramesh

yang shaohua
Frequent Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

Hi Ramesh

 I confirm that I BLOCK the signal in mainthread, and UNBLOCK in new thread, but cann't receive the signal in new thread.

but if I use pthread_kill to sent the alarm signal directly to the new thread, the ALARM signal can be received by the new thread.

 

thanks

yang

yang shaohua
Frequent Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

In fact, I didn't use SIG_UNBLOCK . I just keep the original setting in old_signal_set, coz by default the ALARM is not blocked, so after block, I reset the original setting for unblock action. please refer to :

 

static sigset_t sig_set;
static sigset_t old_sig_set;

 

void BlockSignalAlarm()
{
  sigemptyset( &sig_set );
  sigaddset( &sig_set,SIGALRM );   
  int err = pthread_sigmask( SIG_BLOCK, &sig_set, &old_sig_set ); 
  if( err != 0 )
    printf("error %d occured when block signal alarm", err );
  else  
    printf("block signal alarm");
}

 

void UnblockSignalAlarm()
{
  int err = pthread_sigmask(SIG_SETMASK,&old_sig_set,NULL);
  if( err != 0 )
    printf("error %d occured when unblock signal alarm", err );
  else
    printf("unblock signal alarm") ;
}

 

after the process started, I call BlockSignalAlarm to keep the old_sig_set status firstly.

 

 

 

rchaurasiya
Occasional Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

Hi yang,

 

I have left my program running in loop for a while, which uses routines you have shown here and I dont seem to see it failing. I presume those timing windows would have been taken care of.

Are you able to easily reproduce this? Would it be possible to share the full program which failed for you?

 

Thanks, Ramesh

yang shaohua
Frequent Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

Hi,Ramesh

 It is my fault, I found the code can run correctly on another HP ITA64 machine. but failed on my certain machine although it is the same HP ITA64.

 why?

 

yang

rchaurasiya
Occasional Advisor

Re: Why SIGALRM can't happen in thread on HP-UX?

I have edited my first response to clarify - signal going to process instead of thread was the main reason for original problem you mentioend. If you are facing this issue even after ensuring that signal should come to a particular thread, there should be something worth  taking a closer look. Looking at your program would be helpful yang.

 

Thanks, Ramesh

Dennis Handly
Acclaimed Contributor

Re: Why SIGALRM can't happen in thread on HP-UX?

> I just keep the original setting in old_signal_set, coz by default the ALARM is not blocked

 

You might want to try my SIG_UNBLOCK fragment.