[EMAIL PROTECTED] wrote:
Straight from the BUGS section of the threads module POD:
"Creating threads inside BEGIN blocks (or during the compilation phase in
general) does not work. (In Windows, trying to use fork() inside BEGIN
blocks is an equally losing proposition, since it has been implemented in
very much the same way as threads.)"
So, *don't* do this (yet). One good alternative I can think of off the
top of my head to minimize cloned memory is:
use Thread::Use. It's a nice package that allows you control of when
modules are 'require'd & 'import' method is called. In most cases, the
main thread doesn't need all the modules specified, just your worker
threads.
-Eric
> good, I am trying to do this way: creating a worker-thread without modules
> in BEGIN{} block. The problem is how can main programm and this thread
> communicate with each other and share variables, arrays and hashes?
> Using shared variables not working for me. I have something like this:
> BEGIN{
> use strict;
> use threads;
> use threads::shared;
> use warnings;
> threads->new("worker"); #
> sub worker {
> while (1) {
> # do something
> sleep(1);
> }
> }
> }
> use strict;
> use warnings;
> use Win32::Internet; # some modules
> use DBI;
> use Win32::Clipboard;
> use MIME::Base64;
> use Compress::Zlib;
> use Win32;
> use Win32::Sound;
> use Tie::IxHash;
> while(1){
> # do something
> sleep 1;
> }