Thread Threads + Semaphore ??? (2 answers)
Opened by pearl-man at 2006-02-24 12:00

pearl-man
 2006-02-24 12:00
#63244 #63244
User since
2005-07-25
65 Artikel
BenutzerIn
[default_avatar]
Warum funzt das nicht??

Code: (dl )
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();
}


help\n\n

<!--EDIT|pearl-man|1140775258-->

View full thread Threads + Semaphore ???