are you sharing the variables you need for communication before you
create the thread? If you use my in a BEGIN block it gets undef'ed
see my example
#!/usr/bin/perl
$bar = 1;
sleep 1;
$bar = 0;
undef $bar;
for ($i = 0;$i < 10;$i++)
{
print "String i is $i\n\n";
}
undef $foo;
#sleep 2; # this causes a strange exceptin on winblows.
BEGIN
{
use threads;
use threads::shared;
# create global variable foo
$foo = 1;
# my $foo : shared = 1; # this will become undef'ed as soon as
the BEGIN is finished
$bar = 0;
share ($foo);
share ($bar);
$thr = threads->new(
sub
{
$count = 0;
while($foo)
{
if ($bar)
{
print "\rcount: $count";
}
$count++;
}
print "thread closing\n\n";
})->detach();
}
On Mon, 12 Jul 2004 17:36:14 +0200, Pavel <du4mi@xxxxxx> wrote:
> Hello Jesse,
>
> Monday, July 12, 2004, 5:10:40 PM, you wrote:
>
> JS> Scandeps doesn't seem to be doing the trick with WxPerl. I needed
> >>pp -M Wx -M Wx::App -M Wx::DND -M Wx::DocView -M Wx::FS -M Wx::Grid
> JS> -M Wx::Help -M Wx::Html -M Wx::MDI -M Wx::Print -M Wx::Socket -M
> JS> Wx::Calendar -o foo.exe foo.pl
>
> JS> Also for those thread guru's out there. Is there a better way to deal
> JS> with "thread bloat" and OO syntax (e.g. use base (<PKG>);)? Right now
> JS> I'm using a BEGIN{} block so the other imported packages don't get
> JS> Cloned into my thread. My begin block is working fine, but because
> JS> I'm using a global variable to tell my thread to shutdown nicely, I
> JS> get scalar leaks. I'd like my worker thread to be as small as
> JS> possible, so if you guys have any tricks for that I'd appreciate it.
> JS> I played with Thread::Needs a bit, but its kind of scary. Is there a
> JS> good way to unload a module loaded with use?
>
> JS> Great job on Par guys, it's my favorite package.
>
> JS> -jess
>
> sorry for offlist. I have written some gui-programms that use thread and
> tryed to start thread without any module loaded in BEGIN block. But so
> this thread and main programm cannt communicate with each other.
> I have post this question already many times, but got no right
> answers. May be you will have more luck.
> my posts were:
> http://www.google.com/search?num=100&hl=en&q=du4mi+%28threads+OR+ithreads%29
>
> please tell me if you solve this problem
>
> Thanks in advance!
>
> --
> Best regards,
> Pavel mailto:du4mi@xxxxxx
>
>
|