Subj : Re: killing thread To : comp.programming.threads From : Vitale Ferruccio Date : Wed Aug 10 2005 06:16 pm Probably after some hours spent with gcc, I start to slow down :-) I'll try to explain better: my first thread, thread_execute should execute an external command, using a popen and reading program's stdout, until this command terminates. On the other side, thread_sleep should wait for some seconds and, if the external program is still running, it kills and terminate its execution. With this proposed solution, the mutex is locked by one of the two threads, which doesn't permit the execution of the other one.. right? :-? Does this solution permit comtemporary execution? If not, as I think, how could I do? Ferruccio On 2005-08-10 17:34:25 +0200, Joe Seigh said: >> > Assuming you have a signal handler and you're using the signal to interrupt > a syscall, you may have a race condition. How do you know the thread > in question > is in sleep()? You don't. If the signal occurred before the sleep then > what you're seeing is allowable. > > Use pthread_cond_signal and pthread_cond_timedwait with a "signaled" flag. > > ts.tv_sec = time() + 200; > ts.tv_nsec = 0; > pthread_mutex_lock(&mutex); > while (!signaled) > pthread_cond_timedwait(&cvar, &mutex, &ts); > pthread_mutex_unlock(&mutex); > > > pthread_mutex_lock(&mutex); > signaled = 1; > pthread_cond_signal(&cvar); > pthread_mutex_unlock(&mutex); > -- /dev/zero Unix Power @ Your Service http://www.devzero.it .