Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > new Thread cann...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 10955 of 11065
Post > Topic >>

new Thread cannot work

by happytown277@[EMAIL PROTECTED] Apr 17, 2008 at 06:32 PM

Hi, buddies.
The code below can't work on my WindowsXP with SP2:

===============
#!/usr/bin/perl

	use Thread qw/async yield/;

	my $var = 0;

	sub abump {
		lock $var;
		if ($var == 0) {
			yield;
			$var++;
		}
	}

	my $t1 = new Thread \&abump;
	my $t2 = new Thread \&abump;

	for my $t ($t1, $t2) {
		$t->join;
	}

	print "var is $var\n";
===============
It show me this information below after I run the code:
        "Undefined subroutine &threads::new called at E:\test\learnperl
\thread.pl line 15."

And line 15 is:
        my $t1 = new Thread \&abump;

I test the code under Linux, but the result is ways:
"var is 0";

So, what is wrong?

BTW: the code is one example of "Programming Perl" (third edition).
And it is in chapter "Threads".

===============
Thanks anyway in advance.

Best wishes

happytown277




 3 Posts in Topic:
new Thread cannot work
happytown277@[EMAIL PROTE  2008-04-17 18:32:49 
Re: new Thread cannot work
chas.owens@[EMAIL PROTECT  2008-04-18 06:39:17 
Re: new Thread cannot work
happytown277@[EMAIL PROTE  2008-04-18 03:08:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 23:27:01 CDT 2008.