Re: Threads and file-scoped lexicals

[email protected] (Chaim Frenkel) 26 Aug 2000 23:59:22 -0400
Newsgroups perl.perl6.language.flow
Message-ID <[email protected]>
Thread shared variables will have to be declared.

Perhaps
	my $foo :shared;

Otherwise, the variable refers to thread specific storage.

Up for grabs is what the variable contains upon thread start. undef
or a copy-on-write version of the original.

<chaim>

>>>>> "SWM" == Steven W McDougall <[email protected]> writes:

SWM> Do separate threads 
SWM> - all see the same file-scoped lexicals
SWM> - each get their own file-scoped lexicals


SWM> #!/usr/local/bin/perl

SWM> use Threads;

SWM> my $a = 0;

SWM> my $t1 = Thread->new(\&inc_a);
SWM> my $t2 = Thread->new(\&inc_a);

SWM> $t1->join;
SWM> $t2->join;

SWM> print "$a";

SWM> sub inc_a
SWM> {
SWM>     $a++;
SWM> }

SWM> What should the output be? 0? 1? 2?


SWM> - SWM



-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
[email protected]				               +1-718-236-0183