CORBA-omniORB
view release on metacpan or search on metacpan
omnithreads/t/free2.t view on Meta::CPAN
use strict;
use warnings;
BEGIN {
if ($ENV{'PERL_CORE'}){
chdir 't';
unshift @INC, '../lib';
}
use Config;
if (! $Config{'useithreads'}) {
print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
exit(0);
}
}
use ExtUtils::testlib;
use omnithreads;
BEGIN {
eval {
require omnithreads::shared;
import omnithreads::shared;
};
if ($@ || ! $omnithreads::shared::threads_shared) {
print("1..0 # Skip: omnithreads::shared not available\n");
exit(0);
}
$| = 1;
print("1..78\n"); ### Number of tests that will be run ###
};
my $TEST;
BEGIN {
share($TEST);
$TEST = 1;
}
ok(1, 'Loaded');
sub ok {
my ($ok, $name) = @_;
lock($TEST);
my $id = $TEST++;
# 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);
}
### Start of Testing ###
# 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 %READY;
share(%READY);
# Init a thread
sub th_start {
my $tid = omnithreads->tid();
ok($tid, "Thread $tid started");
omnithreads->yield();
my $other;
{
lock(%READY);
# Create next thread
if ($tid < 17) {
my $next = 'th' . ($tid+1);
my $th = omnithreads->create($next);
} else {
# Last thread signals first
th_signal(1);
}
# Wait until signalled by another thread
while (! exists($READY{$tid})) {
cond_wait(%READY);
}
$other = delete($READY{$tid});
}
ok($tid, "Thread $tid received signal from $other");
omnithreads->yield();
}
# Thread terminating
sub th_done {
my $tid = omnithreads->tid();
lock($COUNT);
$COUNT++;
cond_signal($COUNT);
ok($tid, "Thread $tid done");
}
# Signal another thread to go
sub th_signal
{
( run in 1.279 second using v1.01-cache-2.11-cpan-d80b1682f3f )