Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/src/cmd/perl/ext/Thread/unsync3.tx

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


BEGIN {
    eval { require Config; import Config };
    if ($@) {
	print "1..0 # Skip: no Config\n";
	exit(0);
    }
}

use Thread;

$| = 1;

srand($$^$^T);

sub whoami {
    my $thread = shift;
    print $thread;
}

sub uppercase {
    my $count = 100;
    while ($count--) {
	my $i = int(rand(1000));
	1 while $i--;
	print "A";
	$i = int(rand(1000));
	1 while $i--;
	whoami("B");
    }
}
	
sub lowercase {
    my $count = 100;
    while ($count--) {
	my $i = int(rand(1000));
	1 while $i--;
	print "x";
	$i = int(rand(1000));
	1 while $i--;
	whoami("y");
    }
}
	
sub numbers {
    my $count = 100;
    while ($count--) {
	my $i = int(rand(1000));
	1 while $i--;
	print 1;
	$i = int(rand(1000));
	1 while $i--;
	whoami(2);
    }
}
	
new Thread \&numbers;
new Thread \&uppercase;
new Thread \&lowercase;

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.