Also your code is quite simple, meaning it uses modules that "probably" are quite thread safe. I would next start trying to run something like WWW::Mechanize, or LWP::UserAgent in the threads, and see what they add to the garbage leftovers. Maybe Win32 does a better job with garbage collection than linux?
I don't understand what you mean by this? Shared vars are tied. Every time you reference one, the current value is retrieved from the master copy.
In a simple example you are right. I'm talking about (and I should have mentioned it) using GUI's with threads. Gui's will allow you to tie, but that won't work across threads. Here is a simple example, the count is not automatically reflected to the thread.
#!/usr/bin/perl use strict; use warnings; use threads; use threads::shared; use Tk; my $count:shared=0; my $thread = threads->new( \&launch_thread )->detach; my $mw = MainWindow->new(); $mw->geometry("600x400+100+100"); my $l1 = $mw->Label(-textvariable => \$count)->pack(); MainLoop; sub launch_thread { while (1){ $count++; print "$count\n"; sleep 1; } }
I'm not very good with a simple Tie, but the following dosn't trigger the fetch or store, in a non-gui script.
#!/usr/bin/perl use strict; use warnings; use threads; use threads::shared; use Tie::Watch; my $count:shared=0; my $thread = threads->new( \&launch_thread )->detach; my $watch = Tie::Watch->new( -variable => \$count, # -debug => 1, -fetch => \&fetch, -store => \&store, -destroy => sub {print "Final value=$count.\n"}, ); while(1){} sub launch_thread { while (1){ $count++; print "$count\n"; sleep 1; } } sub store { print "changed\n"; } sub fetch{ print "fetched @_\n"; }
Maybe you can make the simple Tie report a store?
In reply to Re^3: Threads question
by zentara
in thread Threads question
by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |