in reply to Re^3: Why do my threads sometimes die silenty?
in thread Why do my threads sometimes die silenty?
If you added a sleep to the main thread (at the same position as the commented out join, then you would see the error because the slave thread would get a timeslice will the main thread was sleeping.Interesting... indeed, if I put a sleep at the end of the script, I do indeed see the error.
But why would you comment out the join?I did this to simulate a situation where the main thread gets stuck waiting for some message from the slave thread, which never actually comes because the thread died before sending it. In that situation, the master thread never gets a chance to execute a join(), and so, I don't get to see the error message, even if I do Crtl-C. Or so I thought... Your comment leads me to think that this is not the case. Indeed, here's a piece of code that proves that:
When I execute this, I get:use strict; use threads; use threads::shared; my $signal = undef; share($signal); my $fct = sub { require Blah; Blah->import(); $signal = 1; }; my $thr = threads->new($fct); while (!$signal) { print "Sleeping and waiting for signal from slave thread\n"; sleep(1); } print "Got message from slave thread\n"; $thr->join();
In other words, the master does get stuck waiting for a message that will never come, but the error is still printed. Like I said earlier, I am having difficulty reproducing the exact circumstances "in vitro". I'll keep working at it and post new developments here. One difference between my app and the above simple example is that I am actually using a Thread::Pool to run the slave.Sleeping and waiting for signal from slave thread Thread 1 terminated abnormally: Can't locate Blah.pm in @INC (@INC con +tains: etc... Sleeping and waiting for signal from slave thread Sleeping and waiting for signal from slave thread etc...
|
|---|