NAME
Thread - using wxPerl with threads
SYNOPSIS
# the order of these use()s is important
use threads;
use threads::shared;
use Wx;
my $DONEEVENT : shared = Wx::NewEventType;
my $worker = threads->create( \&work );
# create frames, etc
my $frame = Wx::Frame->new( ... );
EVTCOMMAND( $frame, -1, $DONEEVENT, \&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, $DONEEVENT, $result );
Wx::PostEvent( $frame, $threvent );
}
# event handler
sub OnCreateThread {
# @ = () is necessary to avoid "Scalars leaked"
my( $self, $event ) = @; @ = ();
threads->create( ... );
}
DESCRIPTION
Threaded GUI application are somewhat different from non-GUI threaded
applications in that the main thread (which runs the GUI) must never
block. Also, in wxWidgets, no thread other than the main thread can
manipulate GUI objects. This leads to a hybrid model where worker
threads must send events to the main thread in order to change the GUI
state or signal their termination.
OOrrddeerr ooff mmoodduullee llooaaddiinngg
It's necessary for "use Wx" to happen after