starting threads without importing modules

[email protected]
Newsgroups perl.ithreads
Message-ID <[email protected]>
Hello PerlDiscuss,

I have perl script with threads-workers. Because I use many modules
in the script the start take a lot of time, although the worker self
needs only two modules.

I'm trying to speed up starting threads, avoiding import non-needed
modules, so I put "threads->new.." in BEGIN{} block before
use Some::Module statements ( as suggested in this good article:
http://perlmonks.org/index.pl?node_id=288022 ).

But now I can't access variables and objects, which was initializing
in BEGIN block.

I know about Thread::Needs, but it release memory after the start,
therefore it is not the solution for me (?).

WinXP, ActiveState 5.8.3

Thanks for your help.


--------------------------------------------------------------
BEGIN{
    use threads;
    use threads::shared;
    use strict;
    use warnings;
    my $var : shared = 0;
    threads->new("main_thread");  #

    sub main_thread {
        for (1..10) {
            threads->new( "load");
        }
    }
    sub load {
        while (1) {
            {
              lock $var;
              print $var++ . "\n";
            }
            sleep 2;
        }
    }
}

use Win32::Internet;  # some modules
use Win32::GUI;
use Win32::Internet;
use DBI;
use Win32::GUI::Grid;
use Win32::OLE;
use Win32::GUI::AxWindow;
use Win32::Clipboard;
use MIME::Base64;
use Compress::Zlib;
use Win32;
use Win32::Sound;
use Tie::IxHash;

while(1){
    {
        lock $var;
        $var--;
    }
    sleep 1;
}
---------------------------------------------------------------

-- 

Best regards,
 du4mi                            mailto:[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.