Well I ran your code on linux( upping the count to 5000), and it starts out at about 4.4% mem (I have a gig of ram). After 2 minutes, it was up to 12.4 % ram. That is roughly a doubling of mem every minute...... that's what I'm talking about.

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?


I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re^3: Threads question by zentara
in thread Threads question by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.