for those who get it wrong, it's working now for me, if u find any bugs and errors, plz do update me.
#!/usr/bin/perl use File::Find; use threads qw/async/; my $source = "C:/DManager"; $destination = "E:/Job_server/Helix_destination"; my @t; ######## my $workers = 1; #number of workers my $sequence = 0; my $threads = 0; #number of threads my $done = 0; my $resources = 5; # set how mant jobs u want to run my $count =0; my @fin_threads; ######## find(\&copydir, $source); ### find #### sub copydir { my ($parent, $child, $filename, $mpeg); # print "Now starting \n"; if (($_ ne ".") and ($_ ne " ")) { $mpeg = $_ if (($_ =~ /.*\..*/) && ($_ !~ /.*\.db/)); if ($_ !~ m/\.*\.\w+/) { $parent = "$File::Find::dir"; $child = "$File::Find::name"; print "Folder name : $_\n"; #print "Parent Folder : ". $parent."\n"; print "Child Folder : ". $child ."\n"; } } if ($mpeg) { print "filename : $mpeg\n"; my $rm; #my ($rm) = $mpeg =~ /((.*)\.)/; #$rm =~ s/\.//; #$rm .= ".rm"; my $path = $File::Find::name; $path =~ s/\//\\/g; $rm = $path; $rm =~s/\..*/\.rm/g; &CheckQ(); StartQ($mpeg, $rm, $path); } } sub StartQ { #print "Now in StartQ \n"; my ($input, $output, $path) = @_; $threads++; print "pushing to the Thread ". $threads ."\n"; eval { #push @t, async { push @t, async { Dummy_process(); }; }; if (!$@) { $fin_threads[$workers] = 0; $workers++; #sleep 2; } else { $threads--; } #print "running process \n"; } sub CheckQ { print "Workers working : ". $workers. "\n"; if ($workers >= 5) { print "Wiating for one of the worker to finish the job\n"; print "Checking threads for safe exit \n"; SafeExit(); for (@t) { #$_->done() or sub {$workers--; return}; #if (!$@) { #if (!$_->join) { if ($fin_threads[$workers] != 1) { print "Work in process checking other workers : Wo +rkers : $workers\n"; print $@ ."\n"; if ( @t <6 ) { $workers = @t; return; } } else { $workers--; print "Worker finished working : Workers : $worker +s\n"; return; } } } else { return; } } sub SafeExit { print "\n In Safe Exit\n"; for (@t) { eval{ #if($_->join) { if ($fin_threads != 1) { print "A thread already joined in exit status\n"; print "\n $count \n"; print "\n $_\n"; splice(@t, $count, 1); sleep 5; $count++; } #else # { # next; # } }; if ($@) { } } } ###################################################################### +######################## #for checking the Threads only. sub Dummy_process { print "Thread: ". threads->self->tid ."Started with working ". $wo +rkers. "\n"; sleep 2; $fin_threads[$workers] =1; }

In reply to Re^3: catching Thread Exits - how ? by opensourcer
in thread catching Thread Exits - how ? by opensourcer

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.