As suggested by Dave Mitchell, adding yield()s at
Jarkko Hietaniemi [Sun, 12 May 2002 13:50:20 +0000 (13:50 +0000)]
appropriate spots helps non-preemptive thread
implementations, like the GNU pth.  Tested at NetBSD
by Martin Weber <Ephaeton@gmx.net>.

p4raw-id: //depot/perl@16555

ext/threads/t/basic.t
ext/threads/t/list.t
ext/threads/t/thread.t

index eca5c97..fa9a655 100755 (executable)
@@ -78,6 +78,7 @@ sub test4 { ok(6,1,"Detach test") }
 my $thread1 = threads->create('test4');
 
 $thread1->detach();
+threads->yield; # help out non-preemptive thread implementations
 sleep 2;
 ok(7,1,"Detach test");
 
index e5929ed..f0995a1 100644 (file)
@@ -47,6 +47,7 @@ $thread->join();
 ok(5, scalar @{[threads->list]} == 1);
 
 $thread = threads->create(sub { ok(6, threads->self == (threads->list)[1])});
+threads->yield; # help out non-preemptive thread implementations
 sleep 1;
 ok(7, $thread == (threads->list)[1]);
 $thread->join();
index 85bf2cd..435f3bd 100644 (file)
@@ -54,6 +54,7 @@ sub dorecurse {
 {
     # test that sleep lets other thread run
     my $t = threads->new(\&dorecurse, "ok 11\n");
+    threads->yield; # help out non-preemptive thread implementations
     sleep 1;
     print "ok 12\n";
     $t->join();