This commit is contained in:
Ryan 2025-12-07 22:44:24 -05:00
parent d0ff801e7d
commit ff1745df3a
1 changed files with 9 additions and 4 deletions

View File

@ -49,13 +49,13 @@ for(my $y=0; $y<@lines; $y++) {
}
my $ends = 0;
my $numworkers = 16;
my $numworkers = $ARGV[0] || 16;
my $queue = Thread::Queue->new();
my @threads;
$queue->enqueue($startpos);
for(my $i=0; $i<$numworkers; $i++) {
push @threads, threads->create(\&process);
push @threads, threads->create(\&process, $i);
}
foreach my $thread (@threads) {
@ -66,8 +66,12 @@ foreach my $thread (@threads) {
print "$ends total ends\n";
sub process {
my $threadid=shift(@_);
my $ends = 0;
while(my $pos=$queue->dequeue_timed(5)) {
if($threadid == 0) {
print $queue->pending() . " pending\n";
}
my($x,$y)=@$pos;
for(;;) {
@ -77,8 +81,9 @@ sub process {
last;
} elsif($rows[$x][$y] eq '^') {
$queue->enqueue([$x-1, $y]);
$queue->enqueue([$x+1, $y]);
last;
$x++;
#$queue->enqueue([$x+1, $y]);
#last;
}
}
}