#! /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