Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use threads;
- use threads::shared;
- my @arr : shared;
- @arr = (1..300);
- my $total = 10;
- my @build;
- for (0..$total-1){
- $build[$_] = threads->create(&thread);
- }
- for(@build){
- $_->join;
- }
- sub thread{
- while(@arr){
- # {lock(@arr); $a = shift @arr;}
- my $a = shift @arr;
- sleep rand 5;
- print "$an";
- }
- }
Add Comment
Please, Sign In to add comment