Threads and signals. Delicious. Tweak change 28168 to add a local
Nicholas Clark [Fri, 12 May 2006 11:47:40 +0000 (11:47 +0000)]
signal handler in the sleeping thread, because some operating systems
deliver the SIGINT to that thread rather than the signalling thread.

p4raw-id: //depot/perl@28174

ext/threads/t/kill.t

index 6f632bd..0e931f1 100644 (file)
@@ -90,7 +90,10 @@ sub thr_func {
 
     # Thread sleeps until signalled
     ok(1, 'Thread sleeping');
-    sleep(5);
+    {
+       local $SIG{'INT'} = sub {};
+       sleep(5);
+    }
     # Should not go past here
     ok(0, 'Thread terminated normally');
     return ('ERROR');
@@ -109,6 +112,8 @@ threads->yield();
 
 # Interrupt thread's sleep call
 {
+    # We can't be sure whether the signal itself will get delivered to this
+    # thread or the sleeping thread
     local $SIG{'INT'} = sub {};
     ok(kill('INT', $$) || $^O eq 'MSWin32', q/Interrupt thread's sleep call/);
 }