#! perl -slw use strict; use threads stack_size => 4096; use threads::shared; open STDOUT, '>', 'nul' or die; my $shared1 :shared = 1; my $shared2 :shared = 2; my $shared3 :shared = 3; my @counts :shared = (0)x3; sub FUD1 { ## According to ikegami ## $shared = "abc"; # Can cause scalar type conversion ## leading to [867132|a segfault] while( 1 ) { my $chance = rand; $shared1 = $chance < 0.333333333 ? "fred$chance" : $chance < 0.666666666 ? $chance : int( $chance * 100 ); lock @counts; ++$counts[0]; } } sub FUD2 { ## According to ikegami ## [867127|my $ref = \$shared; # Increments ref count] ## leading to [867132|premature deallocation] while( 1 ) { { my $ref = \$shared2; } die unless defined $shared2; lock @counts; ++$counts[1]; } } sub FUD3 { ## According to ikegami ## [867127|print "$shared\n"; # Implicit type conversion] ## leading to [867132|a segfault] while( 1 ) { print "$shared3"; ++$shared3; lock @counts; ++$counts[2]; } } async( \&FUD1 )->detach for 1 .. 100; async( \&FUD2 )->detach for 1 .. 100; async( \&FUD3 )->detach for 1 .. 100; printf STDERR "\r@counts" while sleep 1; __END__ C:\test>ikeFUD1.pl 108788021 167537823 101758175 Terminating on signal SIGINT(2)