in reply to Why is my counter not updating in a threaded application?
You are not threading, you are forking. Your incrementing of the counter only happens in the child.
If you move the counter before the $pm->start and next LOOP, it will increment properly as that runs in the main process:
our $ctr = 0; say "processing duplicates..."; LOOP: foreach my $pid (@duplicated) { unless ($ctr % 1000) {say $ctr;} $ctr++; $pm->start and next LOOP; # do the fork #do stuff $pm->finish; # exit the child process }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is my counter not updating in a threaded application?
by cormanaz (Deacon) on Mar 29, 2024 at 20:47 UTC | |
by hv (Prior) on Mar 29, 2024 at 22:51 UTC | |
by Corion (Patriarch) on Mar 29, 2024 at 21:27 UTC |