Thread Das Modul "forks" (3 answers)
Opened by Gast at 2008-06-06 10:37

Gast Gast
 2008-06-06 10:37
#110802 #110802
Hi!

Gibt es eine Dokumentation, in der die Methoden von forks erklärt werden?
Oder kann mir dazu jemand helfen:

Code (perl): (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
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl
use forks;
use warnings;
use strict;

my $thread_1 = threads->new( \&eins );
my $thread_2 = threads->new( \&zwei );

sub eins {
        my $sum = 0;
        foreach ( 0..99) {
                print "th_1 : ", $_, "\n";
                $sum += $_;
                select( undef, undef, undef, 0.05 );
        }
        return $sum;
} 
sub zwei {
        my $sum = 0;
        foreach ( -99..0 ) {
                print "                             th_2 : ", abs( $_ ), "\n";
                $sum += $_;
                select( undef, undef, undef, 0.05 );
        }
        return $sum;
} 

my $result_1 = $thread_1->join();
my $result_2 = $thread_2->join();
print "\n", $result_1 + $result_2, "\n\n\n";


print "\nowntid :", threads->tid, "\n";
print "tid 1 :", $thread_1->tid, "\n";
print "tid 2 :", $thread_2->tid, "\n";
print "\nself :",threads->self, "\n";


# $thr->kill('SIGUSR1');
# threads->detach;
# $thread->detach;
# my $threadx = threads->object( $tidx );
# my @running = threads->list(threads::running);
#  $_->join() foreach (threads->list(threads::joinable));
#  $_->join foreach threads->list; #block until all threads done


Was macht detach bzw. die anderen hier auskommentieren Funktionen?
Was kann ich mit owntid, tid 1, tid 2 anfangen?
Wie kann ich von $tread_1 aus, sobald dort eine bestimmte Bedingung erreicht ist, $thread_2 beenden?

View full thread Das Modul "forks"