From: Malcolm Beattie Date: Fri, 10 Oct 1997 17:23:41 +0000 (+0000) Subject: Tweak a few Thread tests. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=609f3ea94a9fd133db89bb2c89cce59f951609e2;p=p5sagit%2Fp5-mst-13.2.git Tweak a few Thread tests. p4raw-id: //depot/perlext/Thread@121 --- diff --git a/io.t b/io.t index 8818318..8ade265 100644 --- a/io.t +++ b/io.t @@ -9,11 +9,17 @@ sub reader { return 0; } +print <<'EOT'; +This test starts up a thread to read and echo whatever is typed on +the keyboard/stdin, line by line, while the main thread counts down +to zero. The test stays running until both the main thread has +finished counting down and the I/O thread has seen end-of-file on +the terminal/stdin. +EOT + $r = new Thread \&reader; -$count = 20; +$count = 10; while ($count--) { sleep 1; print "ping $count\n"; } - - diff --git a/join2.t b/join2.t new file mode 100644 index 0000000..99b43a5 --- /dev/null +++ b/join2.t @@ -0,0 +1,12 @@ +use Thread; +sub foo { + print "In foo with args: @_\n"; + return (7, 8, 9); +} + +print "Starting thread\n"; +$t = new Thread \&foo, qw(foo bar baz); +sleep 2; +print "Joining with $t\n"; +@results = $t->join(); +print "Joining returned @results\n"; diff --git a/sync2.t b/sync2.t index 75e814f..0901da4 100644 --- a/sync2.t +++ b/sync2.t @@ -10,8 +10,9 @@ sub single_file { print "Uh oh: $who entered while locked by $global\n" if $global; $global = $who; print "["; - for ($i = 0; $i < int(50 * rand); $i++) { + for ($i = 0; $i < int(10 * rand); $i++) { print $who; + select(undef, undef, undef, 0.1); } print "]"; $global = undef; @@ -19,30 +20,33 @@ sub single_file { sub start_a { my ($i, $j); - for ($j = 0; $j < 50; $j++) { + for ($j = 0; $j < 10; $j++) { single_file("A"); - for ($i = 0; $i < int(50 * rand); $i++) { + for ($i = 0; $i < int(10 * rand); $i++) { print "a"; + select(undef, undef, undef, 0.1); } } } sub start_b { my ($i, $j); - for ($j = 0; $j < 50; $j++) { - single_file("A"); - for ($i = 0; $i < int(50 * rand); $i++) { + for ($j = 0; $j < 10; $j++) { + single_file("B"); + for ($i = 0; $i < int(10 * rand); $i++) { print "b"; + select(undef, undef, undef, 0.1); } } } sub start_c { my ($i, $j); - for ($j = 0; $j < 50; $j++) { - single_file("c"); - for ($i = 0; $i < int(50 * rand); $i++) { - print "C"; + for ($j = 0; $j < 10; $j++) { + single_file("C"); + for ($i = 0; $i < int(10 * rand); $i++) { + print "c"; + select(undef, undef, undef, 0.1); } } } @@ -50,10 +54,16 @@ sub start_c { $| = 1; srand($$^$^T); +print <<'EOT'; +Each pair of square brackets [...] should contain a repeated sequence of +a unique upper case letter. Lower case letters may appear randomly both +in and out of the brackets. +EOT $foo = new Thread \&start_a; $bar = new Thread \&start_b; $baz = new Thread \&start_c; print "\nmain: joining...\n"; -$foo->join; -$bar->join; -$baz->join; +#$foo->join; +#$bar->join; +#$baz->join; +print "\ndone\n";