On Wed, 26 Jul 2006, Kristoff Bonne wrote:

> > It would be very helpful if you would post a "complete" example that
> > shows the problem you're having.
> 
> OK. In short a small test-program: (I left out the standard "REAPER"-code).

(``$SIG{CHLD} = \&REAPER'' is an interprocess construct put forth in
perlipc, not an interthread construct.  Not sure what effect you intend it
to have.)

> Now, what I do is change the code so that the main program is in one
> file "thr1.pl" and the thread-code is in a second file "thr1_sub.pm".
> This file is "included" into the main program using a "require" line.

This is a scoping issue, not a threads issue.  Code executed via 'do-FILE',
'require' or 'use' cannot see the lexicals in the enclosing scope of the
doer, the requirer or the user.  Demonstration:

  $ cat require.pl 
  print "require.pl \$a is $a\n";
  1;
  $ perl -e 'my $a = 20; require "./require.pl"; print "main \$a is $a\n"'
  require.pl $a is 
  main $a is 20

> So, in fact, it's exactly the same program, but split up in two files.
> (if you have a lot of threads, this is a lot easier to manage then to
> have everything in one file).
...
> So, the variable "a" is not shared anymore!

Your $a (well, my $a) in main is not the same as the $a in the .pm file.

Regards,
Mike
-- 
cat: .signature: Multihop attempted

Reply via email to