summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xext/threads/t/basic.t8
-rw-r--r--ext/threads/t/free.t28
2 files changed, 27 insertions, 9 deletions
diff --git a/ext/threads/t/basic.t b/ext/threads/t/basic.t
index 1501d77fe0..7e7fecffe7 100755
--- a/ext/threads/t/basic.t
+++ b/ext/threads/t/basic.t
@@ -68,11 +68,11 @@ sub test4 {
{
my $thread1 = threads->create('test4');
$thread1->detach();
+ while ($thread1->is_running()) {
+ threads->yield();
+ sleep 1;
+ }
}
-
-threads->yield; # help out non-preemptive thread implementations
-sleep 2;
-
ok(7, 1, "Detach test");
diff --git a/ext/threads/t/free.t b/ext/threads/t/free.t
index 0e8bd86cd1..3dfc4a12b8 100644
--- a/ext/threads/t/free.t
+++ b/ext/threads/t/free.t
@@ -62,14 +62,17 @@ sub ok {
# Tests freeing the Perl interperter for each thread
# See http://www.nntp.perl.org/group/perl.perl5.porters/110772 for details
-my $COUNT;
-share($COUNT);
+my ($COUNT, $STARTED) :shared;
sub threading_1 {
my $tid = threads->tid();
ok($tid, "Thread $tid started");
- if ($tid < 5) {
+ {
+ lock($STARTED);
+ $STARTED++;
+ }
+ if ($STARTED < 5) {
sleep(1);
threads->create('threading_1')->detach();
}
@@ -95,12 +98,16 @@ sub threading_1 {
}
{
+ $STARTED = 0;
$COUNT = 0;
threads->create('threading_1')->detach();
{
lock($COUNT);
while ($COUNT < 3) {
cond_wait($COUNT);
+ threads->create(sub {
+ threads->create(sub { })->join();
+ })->join();
}
}
}
@@ -109,6 +116,9 @@ sub threading_1 {
lock($COUNT);
while ($COUNT < 5) {
cond_wait($COUNT);
+ threads->create(sub {
+ threads->create(sub { })->join();
+ })->join();
}
}
threads->yield();
@@ -121,7 +131,11 @@ sub threading_2 {
my $tid = threads->tid();
ok($tid, "Thread $tid started");
- if ($tid < 10) {
+ {
+ lock($STARTED);
+ $STARTED++;
+ }
+ if ($STARTED < 5) {
threads->create('threading_2')->detach();
}
@@ -135,11 +149,15 @@ sub threading_2 {
}
{
+ $STARTED = 0;
$COUNT = 0;
threads->create('threading_2')->detach();
+ threads->create(sub {
+ threads->create(sub { })->join();
+ })->join();
{
lock($COUNT);
- while ($COUNT < 3) {
+ while ($COUNT < 5) {
cond_wait($COUNT);
}
}