#!/usr/bin/perl
# 20070127 - fix for get_nn only

my $start_time = time();
print "Hello, World...\n";
use threads ();
use threads::shared ();
my $count : shared = 0;
my @threads;

print "Started on " . localtime($start_time) . "...\n";
push @threads, threads->new(sub { for (1..10000) { lock($count); $count++ } }) for 1..10;
$_->join foreach @threads; # wait for all threads to finish 
print "Ended on " . localtime(time()) . "...\n";

print "count = ", get_nn($count), "\n";

sub get_nn { # perl nice number nicenum add commas
	my ($n) = @_;
	if (length($n) > 3) {
		my $mod = length($n) % 3;
		my $ret = (($mod > 0) ? substr( $n, 0, $mod ) : '');
		my $mx = int( length($n) / 3 );
		for (my $i = 0; $i < $mx; $i++ ) {
			if (($mod == 0) && ($i == 0)) {
				$ret .= substr( $n, ($mod+(3*$i)), 3 );
			} else {
				$ret .= ',' . substr( $n, ($mod+(3*$i)), 3 );
			}
		}
		return $ret;
	}
	return $n;
}

