Leser: 1
4 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 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#! /usr/bin/perl use forks; use strict; use warnings; my $thread1 = threads->new( func( 0 ) ); my $thread2 = threads->new( func( 30 ) ); $thread1->join; $thread2->join; sub func { foreach ( 1..100000 ) { print " " x $_[0], $_, "\n" } return 1; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
01: #! /usr/bin/perl
02: use forks;
03: use strict;
04: use warnings;
05:
06: $| = 1;
07:
08: my $thread1 = threads->new( func( 0 ) );
09: my $thread2 = threads->new( func( 30 ) );
10:
11: $thread1->join;
12: $thread2->join;
13:
14:
15: sub func {
16: foreach ( 1..100000 ) {
17: print " " x $_[0], $_, "\n"
18: }
19: return 1;
20: }
4 Einträge, 1 Seite |