in reply to Re: is ||= threadsafe?
in thread is ||= threadsafe?
Admittedly, I have only waited roughly an hour for this to run, but that is sufficient for 100 threads to explore the possibilities of each your speculative modes of failure, for 100 million plus iterations each. (Ignoring all the other threaded code I've ever written that could have done so)
I consider that a pretty conclusive demonstration that you're talking out your a the top of your head.
Of course you could have tried this trivial test of your speculations yourself, in the same minimal amount of time, before posting such FUD, but that wouldn't meet your apparent motivations.
#! 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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Utter FUD!
by Anonymous Monk on Oct 25, 2010 at 14:56 UTC | |
by BrowserUk (Patriarch) on Oct 25, 2010 at 15:27 UTC | |
by Anonymous Monk on Oct 25, 2010 at 16:18 UTC | |
by BrowserUk (Patriarch) on Oct 25, 2010 at 16:53 UTC | |
by ysth (Canon) on Oct 25, 2010 at 19:19 UTC | |
| |
|
Re^3: Utter FUD!
by ikegami (Patriarch) on Oct 25, 2010 at 16:42 UTC | |
by BrowserUk (Patriarch) on Oct 25, 2010 at 17:02 UTC | |
by ikegami (Patriarch) on Oct 25, 2010 at 17:17 UTC |