use ExtUtils::testlib;
use threads;
-use threads::shared;
+
+BEGIN {
+ eval {
+ require threads::shared;
+ import threads::shared;
+ };
+ if ($@ || ! $threads::shared::threads_shared) {
+ print("1..0 # Skip: threads::shared not available\n");
+ exit(0);
+ }
+
+ local $SIG{'HUP'} = sub {};
+ my $thr = threads->create(sub {});
+ eval { $thr->kill('HUP') };
+ $thr->join();
+ if ($@ && $@ =~ /safe signals/) {
+ print("1..0 # Skip: Not using safe signals\n");
+ exit(0);
+ }
+}
{
package Thread::Semaphore;
BEGIN {
$| = 1;
- print("1..18\n"); ### Number of tests that will be run ###
+ print("1..19\n"); ### Number of tests that will be run ###
};
my $TEST = 1;
# Thread sleeps until signalled
ok(1, 'Thread sleeping');
{
- local $SIG{'INT'} = sub {};
- sleep(5);
+ local $SIG{'INT'} = sub {};
+ sleep(5);
}
# Should not go past here
ok(0, 'Thread terminated normally');
# Create thread
my $thr = threads->create('thr_func');
-ok($thr && $thr->tid() == 1, 'Created thread');
+ok($thr && $thr->tid() == 2, 'Created thread');
threads->yield();
sleep(1);
# Create a thread and send it the semaphore
$thr = threads->create('thr_func2', $sema);
-ok($thr && $thr->tid() == 2, 'Created thread');
+ok($thr && $thr->tid() == 3, 'Created thread');
threads->yield();
sleep(1);
sleep(1);
# Terminate the thread
-ok($thr->kill('TERM'), 'Signalled thread to terminate');
+ok($thr->kill('TERM') == $thr, 'Signalled thread to terminate');
$rc = $thr->join();
ok($rc eq 'OKAY', 'Thread return value');
+ok($thr->kill('TERM'), 'Ignore signal to terminated thread');
+
# EOF