Greatings Respectable Monks....

This is my first attemp in multi-threading so please bear with me.

I have this code
$|++; AUTOLOAD; use strict; use warnings 'all'; use diagnostics; use Win32::OLE qw[in]; use threads; use threads::shared; my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); my @childs; my @up: shared; for (@ARGV){ print "\n$_\n"; push @childs, threads->create("Process_path","$_"); #Process_path($_); } foreach my $child (@childs){ $child->join(); } print @up; sub Process_path{ my ($path) = @_; my @folders = $fso->GetFolder( $path); my $FSize = $fso->GetFolder($path); my $Size = $FSize->size(); print "Size: $Size\n"; my $fCount =0; my $sCount =0; while( @folders ){ my $folder = pop @folders; $fCount += $folder->Files->Count; $sCount += $folder->SubFolders->Count; for my $subFolder ( in $folder->SubFolders ) { $fCount += $subFolder->Files->Count; push @folders, $_ for in $subFolder->SubFolders ; $sCount += $subFolder->SubFolders->Count; }} print "Files : $fCount, folders : $sCount\n"; push (@up, $path.": ".$Size.": ".$fCount.": ".$sCount."."); }
which is the result of marrying This script, that obtains the number of files and folders for a given path, to This one, that uses a multi-threading technique to ping few servers, so that instead of pinging servers the script will obtain the size, number of files and folders of a list of folders/paths/share…etc.

To me, all I have done is replaced the pinging off server with obtaining the file/folders statistics. But I am getting this error;
Free to wrong pool 1a9e940 not 223f80 at C:\Scripts\threads4_wsh.pl li +ne 29. Free to wrong pool 1ab0998 not 223f80 at C:\Scripts\threads4_wsh.pl li +ne 15.
Since this my first attemp with multithreading, I am not sure how to fix it.

Your help and Perls of wisdom, as ever, are higly appreciated.

Thanks.

In reply to Starting multi-threading by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.