5
# Note that the strategy for testing for thread failure here is not very good.
6
# It is very timing dependent. On some systems this test will pass even with a parser
7
# that is not thread safe. There is some amount of luck in getting the non-thread safe
8
# code to crash. As it is now, the test below sucessfully crashes version 0.45 of XML::Bare
9
# seemingly every time I run the test.
13
if( !$@ ) { $threads_ok = 1; }
17
eval("use threads::shared;");
18
if( !$@ ) { $shared_ok = 1; }
23
if( !$threads_ok || !$shared_ok ) {
24
plan skip_all => 'Cannot load threads and/or threads::shared; skipping multithreading tests';
29
use_ok( 'XML::Bare' );
30
threads::shared::share( \$numok );
31
for( my $i=0;$i<20;$i++ ) {
32
threads->create( \&single );
35
my @joinable = threads->list(0);#joinable
36
my @running = threads->list(1);#running
38
for my $thr ( @joinable ) { $thr->join(); }
42
is( $numok, 20, 'All threads completed okay' );
48
for( my $i=0;$i<4000;$i++ ) {
51
$xml .= "<node><n>$n</n></node>";
54
my ( $ob, $root ) = XML::Bare->new( text => $xml );
55
$root = $root->{'xml'};
56
my $nodes = $root->{'node'};
59
for my $node ( @$nodes ) {
60
my $n = $node->{'n'}{'value'};
61
$ok = 0 if( $n ne $arr[ $i ] ); # note ne here instead of !=. Because $a=405.69280607542502; $a!="$a"; But $a=405.69280607542501; $a=="$a"; :(