Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Commit

Permalink
WIP - improving threading support
Browse files Browse the repository at this point in the history
  • Loading branch information
delonnewman committed Jul 13, 2012
1 parent e08a6b1 commit 6adc124
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions magbot
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,12 @@ sub doeach($$) {
threads->create(sub {
my ($url, $fn, @args) = @_;
$fn->($url, @args);
threads->exit;
threads->exit;
}, @_);
}

sub worker {
my ($fn, $q, @args) = @_;

my $kid;
while ( my $url = $q->dequeue ) {
$kid = download $url => $fn, @args;
Expand All @@ -533,10 +532,16 @@ sub doeach($$) {

if ( threads->list > 1 ) {
my @threads = threads->list;
for my $t (@threads) {
if ( $t->tid == threads->tid ) { next }
if ( $t->is_running ) { $t->join }
else { $t->detach }
for my $t (threads->list) {
next if $t->tid == threads->tid;
next if $t->is_detached;

eval {
$t->join;
};
if ( $@ ) {
&log($@);
}
}
}
}
Expand Down

0 comments on commit 6adc124

Please sign in to comment.