Hi,
I've found the following in Wx::Thread:
use threads;
use threads::shared;
use Wx;
my $DONE_EVENT : shared = Wx::NewEventType;
my $worker = threads->create( \&work );
# create frames, etc
my $frame = Wx::Frame->new( ... );
EVT_COMMAND( $frame, -1, $DONE_EVENT, \&done );
$app->MainLoop;
sub done {
my( $frame, $event ) = @_;
print $event->GetData;
}
sub work {
# ... do stuff, create a shared $result value
my $threvent = new Wx::PlThreadEvent( -1, $DONE_EVENT, $result );
Wx::PostEvent( $frame, $threvent );
}
__END__
Well, I've seen that the worker thread is created here before creating the
frames, and I also read in perldoc perlthrtut that this is recommended,
because the threads will be smaller this way.
But in the line
Wx::PostEvent( $frame, $threvent );
I've seen that I need to access $frame, so... shouldn't it be created before
the thread that could access it?
In this case I think
my $worker = threads->create( \&work );
should be put after the line where the frame is created.
I ask this, because I've seen that my program occupies more than 160 MB of
RAM when it uses 4 threads, and only 46 MB of RAM when I use a single thread
and I am trying to make it occupy less.
If I create the threads before creating the frame, the program prints an
error telling that $frame is undefined (but the occupied memory is still 160
MB).
So, does it really matter if I create the threads before creating the GUI or
after?
Thanks.
Octavian