{
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");
# 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();
}
}
{
+ $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();
}
}
}
lock($COUNT);
while ($COUNT < 5) {
cond_wait($COUNT);
+ threads->create(sub {
+ threads->create(sub { })->join();
+ })->join();
}
}
threads->yield();
my $tid = threads->tid();
ok($tid, "Thread $tid started");
- if ($tid < 10) {
+ {
+ lock($STARTED);
+ $STARTED++;
+ }
+ if ($STARTED < 5) {
threads->create('threading_2')->detach();
}
}
{
+ $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);
}
}