threads
view release on metacpan or search on metacpan
use strict;
use warnings;
BEGIN {
use Config;
if (! $Config{'useithreads'}) {
print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
exit(0);
}
}
use ExtUtils::testlib;
sub ok {
my ($id, $ok, $name) = @_;
# You have to do it this way or VMS will get confused.
if ($ok) {
print("ok $id - $name\n");
} else {
print("not ok $id - $name\n");
printf("# Failed test at line %d\n", (caller)[2]);
}
return ($ok);
}
BEGIN {
$| = 1;
print("1..34\n"); ### Number of tests that will be run ###
};
use threads;
if ($threads::VERSION && ! $ENV{'PERL_CORE'}) {
print(STDERR "# Testing threads $threads::VERSION\n");
}
ok(1, 1, 'Loaded');
### Start of Testing ###
ok(2, 1 == $threads::threads, "Check that threads::threads is true");
sub test1 {
ok(3,'bar' eq $_[0], "Test that argument passing works");
}
threads->create('test1', 'bar')->join();
sub test2 {
ok(4,'bar' eq $_[0]->[0]->{'foo'}, "Test that passing arguments as references work");
}
threads->create(\&test2, [{'foo' => 'bar'}])->join();
sub test3 {
ok(5, shift() == 1, "Test a normal sub");
}
threads->create(\&test3, 1)->join();
sub test4 {
ok(6, 1, "Detach test");
}
{
my $thread1 = threads->create('test4');
$thread1->detach();
while ($thread1->is_running()) {
threads->yield();
sleep 1;
}
}
ok(7, 1, "Detach test");
sub test5 {
threads->create('test6')->join();
ok(9, 1, "Nested thread test");
}
sub test6 {
ok(8, 1, "Nested thread test");
}
( run in 3.485 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )