zentara has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I was wondering if anyone could confirm that declaring many scalar shared variables will crash ActiveStatePerl on WindowsXP, or a comparable newer Windows version. I am using the latest ActiveState5.8.7.813 on WindowsME and the following script, will run with $max_chan_prog <=3 , but will crash with a "panic cond_init(0)" for large values like 60. The script runs fine on linux.

So I'm wondering if this just because of poor memory management in WindowsME, or if all Windows OS levels do this. Code in the readmore below.

#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; #############shared hashes for xml processor################# my @chs = (1..99); # setting this to 2 works on windowsME # but will bog down over 3, and crash # at values like 60 my $max_prog_chan = 60; my %days; foreach my $channel(@chs){ foreach my $count(0..$max_prog_chan){ #print "$channel $count\n"; share $days{$channel}{$count}{'channel'}; share $days{$channel}{$count}{'channel_info'}; share $days{$channel}{$count}{'episode_num'}; share $days{$channel}{$count}{'start'}; share $days{$channel}{$count}{'stop'}; share $days{$channel}{$count}{'makedate'}; share $days{$channel}{$count}{'description'}; share $days{$channel}{$count}{'title'}; share $days{$channel}{$count}{'writer'}; share $days{$channel}{$count}{'director'}; share $days{$channel}{$count}{'actors'}; share $days{$channel}{$count}{'rating'}; share $days{$channel}{$count}{'length'}; share $days{$channel}{$count}{'category'}; share $days{$channel}{$count}{'star_rating'}; } } my %shash; share $shash{'go'}; share $shash{'progress'}; share $shash{'channels'}; share $shash{'day'}; share $shash{'data'}; share $shash{'pid'}; share $shash{'die'}; $shash{'go'} = 0; $shash{'progress'} = 0; $shash{'channels'} = @chs; $shash{'day'} = ''; $shash{'data'} = ''; $shash{'pid'} = ''; $shash{'die'} = 0; $shash{'thread'} = threads->new( \&xmlwork); ################################################### ##########shared hash for downloader thread########### my %dhash; share $dhash{'go'}; share $dhash{'progress'}; share $dhash{'output'}; share $dhash{'die'}; $dhash{'go'} = 0; $dhash{'progress'} = 0; $dhash{'output'} = ''; $dhash{'die'} = 0; $dhash{'thread'} = threads->new( \&downthread); ######################################################## #start threads running $shash{'go'} = 1; $dhash{'go'} = 1; #wait <>; ################################################################### ################### xml Thread code below ######################### ################################################################### sub xmlwork{ $|++; while(1){ if($shash{'die'} == 1){ goto END }; if ( $shash{'go'} == 1 ){ print "starting xml\n"; for(1..100){ print "xml->$_\n"; sleep 1; } print "\n\ndone xml\n"; if($shash{'go'} == 0){last} if($shash{'die'} == 1){ goto END }; #after above processing is done $shash{'go'} = 0; #turn off self before returning }else { sleep 1 } } #------------------------------------------------------------ END: #end of thread code block } ##################################################################### ##################################################################### ##################################################################### ################# downloader thread below ########################### ##################################################################### ##################################################################### sub downthread{ $|++; while(1){ if($dhash{'die'} == 1){ goto END }; if ( $dhash{'go'} == 1 ){ for(1..100){ print "\tdload->$_\n"; sleep 1; if($dhash{'go'} == 0){last} if($dhash{'die'} == 1){ goto END }; } #after above processing is done $dhash{'progress'} = 0; $dhash{'go'} = 0; #turn off self before returning }else { sleep 1 } } END: #end of downloader thread block } #------------------------------------------------------------ ###################################################################### +## __END__

Replies are listed 'Best First'.
Re: threaded shared hashes-- linux vs. win32
by pg (Canon) on Sep 17, 2005 at 15:41 UTC

    The program worked 100% normal on Windows XP with Perl 5.8.4 and $max_prog_chan set to 60.

    Once the program done all the processing (seen "xml done" printed on screen.), hit <Enter>, the program completed with no problem, other than the usual standrad warning,

    A thread exited while 3 threads were running, <> line 1.

    Which simply stated a fact.

Re: threaded shared hashes-- linux vs. win32
by zentara (Cardinal) on Sep 17, 2005 at 17:28 UTC
    Thanks alot, I guess I'll have to be like everyone else, and say "Window's Version requires XP". :-)

    I wonder what it is about older window's versions that causes it?

    I was able to get better results on ME, by making a shared HoA, with only a single hashkey, like below, pushing everything in a constant order into the array. But hashes are so much cleaner to use.

    my %days; foreach my $channel(@chs){ @{$days{$channel} } = (); share $days{$channel}; } #and load it like push @{$days{$channel} }, $channel; push @{$days{$channel} }, $count; push @{$days{$channel} }, $channel_info; push @{$days{$channel} }, $episode_num; push @{$days{$channel} }, $start; push @{$days{$channel} }, $stop; ....etc.... ...etc...

    I'm not really a human, but I play one on earth. flash japh
Re: threaded shared hashes-- linux vs. win32
by puploki (Hermit) on Sep 17, 2005 at 14:44 UTC

    What's the output supposed to look like (or, what do you think it should look like)?

    On my WinXP box the output looks like:

    C:\Documents and Settings\alex\Desktop>492870.pl dload->1 starting xml xml->1 dload->2 xml->2 dload->3 xml->3 dload->4 . . . xml->98 dload->99 xml->99 dload->100 xml->100 done xml

    And then it just sort of sits there - I hit Ctrl-C after about 5 minutes. There didn't seem to be any CPU or increasing memory usage over this time either.

      "And then it just sort of sits there"

      It sat there because of that <> at the end of program.