in reply to Re^16: Strange memory leak using just threads (forks.pm)
in thread Strange memory leak using just threads

No, it's not:

use strict; use warnings; use 5.010; use threads; use Chart::Clicker; use Time::HiRes qw(time); my $N = 32; my $t = time; my @thr; push @thr, threads->create( sub { 1; } ) for 1 .. $N; $_->join for (@thr); say time - $t;

Runs in 5.57 sec.

use strict; use warnings; use 5.010; use threads; use Time::HiRes qw(time); my $N = 32; my $t = time; my @thr; push @thr, threads->create( sub { require Chart::Clicker; } ) for 1 .. + $N; $_->join for (@thr); say time - $t;

Requires 34 sec to finish

Replies are listed 'Best First'.
Re^18: Strange memory leak using just threads (forks.pm)
by BrowserUk (Patriarch) on Sep 23, 2010 at 11:54 UTC

    Did you actually read the examples I gave in my post before last?

    To summarise:

    • If you have an app that has worker threads that don't need Tk, and a main thread that does.

      use any moduels required by the workers; spawn the workers; then require Tk in the main thread.

    • Alternatively, it can make sense to spawn a (single) thread that then requires the 'big module' that only it needs; and then require the modules needed by the worker threads before spawning them.

      See the DBI example.

    All of this seems pretty clear from my post before last. To arrive at your interpretation on my intent seems hard.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Let me quote:

      And the tests are not correct BTW. Time required for creating new thread depends on the size of all existing variables.
      Yes. That is an annoying detail of the ithreads implementation. But, it is quite easy to avoid; you just spawn your workers early, and have them require rather than use what they (individually) need.

      So, if worker threads require some heavy module, you have to use it before starting these threads (and I don't mean cases where you need just single worker thread), and it may seriously increase worker threads startup time, and it is not easy to avoid.

        Yes. And if every worker fork needs to modify 1 bit on every 4x page of 1 GB of shared data, it's gonna take forever.

        You show me your use-case, and I'll show you mine.