Subj : Using SIGALRM with pthread To : comp.programming.threads From : gc Date : Wed Jul 27 2005 03:39 pm Hi all, I am writting an application on Linux 2.4.28 using C++ which involvs the use of ALARM signal handling in a multi-threaded program. In my application, there are basically two threads (threads A an B), both started by the main thread. The main thread here doesn't do much job here. Thread A and B share some STL data structures, maps and lists, and there is a unique semaphore (implemented based on the pthread_mutex and pthread_cond) assocaiated with every data structure. I also have a condition variable associated with a pthread_mutex and a pthread_cond. Thread A waits on the condtion variable (pthread_cond_wait) while the Thread B updates the condition variable and sends signals (pthread_cond_signal) to wake up the waiting thead. At the same time, I need to use an ALARM signal (SIGALRM) in thread A to invoke a periodical even handler. I use the signal() function to install the handler for SIGALRM in thread A's constructor. In the SIGALRM handler, I also need to access some variables and data structures from thread A. What frustrates me is that, without turning on the ALARM signal, everything goes well. Whenever I turn on the ALARM signal, I get all kinds of werid errors related to pthread_mutexes. For instance, segmentation fault on pthread_mutex_unlock (unlock the mutex for the conditional variable), or sometimes thread B gets blocked on pthread_mutex_unlock (unlock does not return), or sometimes the whole program halts. These bugs all seem to come from the pthread library, but I think there is something wrong in my code. So, I am not sure if anybody has experience with this or similiar situations. Or does anybody have good resources related to using threads and signals at the same time? Thanks for your help! gc .