I see an issue (actually a crash) on OS X 10.5.5 with my current threading model. see my code snippet below:
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); }
If I eliminate the threading aspect from my code it works fine. Am I handling the thread creation incorrectly?

Thanks, -Paul


In reply to wxPerl and threads by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.