As we're not passing over (or copying in) a NUL, don't need that extra
[p5sagit/p5-mst-13.2.git] / ext / threads / t / kill.t
index 0e931f1..3874db1 100644 (file)
@@ -16,7 +16,26 @@ BEGIN {
 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;
@@ -46,7 +65,7 @@ use threads::shared;
 
 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;
@@ -91,8 +110,8 @@ sub thr_func {
     # 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');
@@ -102,7 +121,7 @@ sub thr_func {
 
 # 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);
 
@@ -164,7 +183,7 @@ ok($sema, 'Semaphore created');
 
 # 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);
 
@@ -182,9 +201,11 @@ threads->yield();
 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