3 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl -w
use Thread;
use Thread::Semaphore;
my $max_parallel_jobs = 3;
my $users_file = "users.txt";
open(USERS, "<$users_file") or die "Could not read $users_file!\n";
my @users = <USERS>;
close(USERS);
my $total_jobs = $#users;
my $sem = Thread::Semaphore->new($max_parallel_jobs);
my @output=();
for my $job (0..$total_jobs){
$sem->down();
my $thread = Thread->new(\&test_user, $users[$job]);
$thread->join();
}
while(<@output>){
print "output: $_";
}
sub test_user
{
chomp($_[0]);
print "USER: $_[0]\tist jetzt an der Reihe!\n";
push(@output, $_[0]);
$sem->up();
}
3 Einträge, 1 Seite |