Thread

Posted on Wed Jun 28 10:59:17 2006 by sam79
thread->join method delays signal reception
I have a perl script with 2 threads. I define a signal handler (for HUP signal) in the main thread. If my main thread is blocked on a join(), the HUP signals sent to the process using unix kill command are blocked until the join method terminate its execution. Is there a way of doing a join system call that doesn't delay signals? Thanks, Samuel
Direct Responses: 2549 | Write a response
Posted on Wed Jun 28 16:16:00 2006 by jdhedden in response to 2548
Re: thread->join method delays signal reception
You could try having the main thread wait on a shared variable prior to attempting the join. The easiest way to do this with using Thread::Queue. Start with:
use threads; use Thread::Queue; my $DONE = Thread::Queue->new();
Have the thread code end by putting its TID onto the done queue:
$DONE->enqueue(threads->tid()); return (...);
In the main code, wait for the thread to finish before attempting a join:
my $tid = $DONE->dequeue(); threads->object($tid)->join();
Direct Responses: 2996 | Write a response
Posted on Mon Sep 11 21:31:16 2006 by cliff in response to 2549
Re: thread->join method delays signal reception
This doesn't seem to help as the main thread blocks on $DONE->dequeue and never sees the signal. The only way I have found around this is to block on sleep which gets woken up by the signal. IMHO, both Thread->Queue->dequeue (which is simply a call to cond_wait) and join should interrupt on a signal. Is the current behaviour deliberate?
Direct Responses: 2997 | Write a response
Posted on Mon Sep 11 21:53:32 2006 by jdhedden in response to 2996
Re: thread->join method delays signal reception
Ah, yes, I see the difficulty. It's true that you would need to have a sleep in a loop:
my $tid; while (! ($tid = $DONE->dequeue_nb())) { sleep(1); } threads->object($tid)->join();
The implementation of delayed/safe signals is deliberate, and is implemented inside the Perl interpreter itself. See 'Deferred Signals' in 'perldoc perlipc' for more details.
Direct Responses: 3156 | Write a response
Posted on Sat Sep 30 02:45:49 2006 by arthurkantor in response to 2997
Re: thread->join method delays signal reception
I ran into a similar problem. It seems to me that whenever a thread is blocked, it's in a safe interruptable point, and should be able to receive signals immediately. Otherwise, I have to check for signals in a while loop (as the solution above), and that seems awkward.
Write a response