If I eliminate the threading aspect from my code it works fine. Am I handling the thread creation incorrectly?use threads; use threads::shared; use Thread::Queue; use Wx; my %thread_hash; share(%thread_hash); # Signal Handler $SIG{'KILL'} = sub { # Tell user we've been terminated printf(" %3d <- Killed\n", threads->tid()); # Detach and terminate threads->detach() if ! threads->is_detached(); threads->exit(); }; # .. frame creation etc. # two buttons being called to start/stop thread task EVT_BUTTON( $self, $self->{start}, \&StartExecThread ); EVT_BUTTON( $self, $self->{stop}, \&StopExecThread ); # .. rest of wx code sub StartExecThread { my ( $self, $event ) = @_; my $threadqueue = Thread::Queue->new(); my $worker = threads->create('CallThread', $self, $threadqueue ); $thread_hash{start_queue} = $threadqueue; $self->{start_thread} = $worker; $thread_hash{start_queue}->enqueue('GO'); } sub StopExecThread { my ( $self, $event ) = @_; if ($self->{start_thread}->is_running()) { # Send a signal to a thread print "Killing thread ...\n"; $self->{start_thread}->kill('KILL'); # toggle button state while thread after thread is stopped $self->{start_button}->Enable(1); $self->{stop_button}->Enable(0); } } sub CallThread { my ( $self, $event ) = @_; # toggle button state $self->{start_button}->Enable(0); $self->{stop_button}->Enable(1); # ... do some stuff # toggle button state $self->{start_button}->Enable(1); $self->{stop_button}->Enable(0); }
Thanks, -Paul
In reply to wxPerl and threads by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |