Problems designing a signal handler in UNIX
I'm trying to create a signal handler thread to handle SIGALRM signals.
The main thread calls the following function before creating any other threads Code:
pthread_t Timer::Init(long _clock_interval_musec) The spawned signal handler thread has the following Run function Code:
void* Timer::TimerHandlerThread(void* args) clock_interval is 50. Is the timer not firing? Did I not set my interval correctly? Did I not proper block the signals ensuring the that the default handler would not take care of them? Any help is welcome. :) |
I'd suggest you ask the mods (via the report button) to move this to the Programming section for better/faster help.
|
Quote:
Code:
void* Timer::TimerHandlerThread(void* args) Timer::Init is the first thing called in main. |
Quote:
1. print out the values you are storing in the timing counters tv_sec/tv_usec 2. make sure that the main thread is not exiting (since its return will end the program) 3. it isn't clear why you are creating the currentTime object on the stack inside the TimerHandlerThread member function |
Quote:
2. It's exiting gracefully, the threads run just fine in the background. In fact, the thread runs, it just blocks in sigwait. 3. It doesn't matter. I implemented the same signal handling technique with sigaction and it works. It's just more writing and less elegant. =/ |
Quote:
I have only tested your code under Linux and it works okay (ie, the signal is caught by the sigwait and it reaches the next lines). You might be on a different system (BSD?). |
Quote:
I'll try running under Linux. |
I suspect that your main code is making use of sleep/usleep. These calls also make use of SIGALRM, which will cause undefined behaviour.
If you use pthread_sigmask instead of sigprocmask (both the main and the handler thread need to block the signal), this may help. |
All times are GMT -5. The time now is 06:02 PM. |