in reply to Re^3: Wx subs and threads
in thread Wx subs and threads

I'm not experienced with the ins and outs out Wx, but look at Reusable threads demo for the basic CLI use. Then in your Wx gui, replace the while loops in the main thread, with Wx timers, etc.

But I can see from your example that you are starting the thread from a Wx button callback:

EVT_BUTTON($self,$self->{button_start}, \&DeployTestThread );
The general rule is to start the thread BEFORE any Wx gui code is invoked. So you may try something like
# Prevents double detach attempts my $DETACHING :shared; #start your thread here before Wx DeployTestThread(); package MyApp;
then your button callback will just set the shared variable
EVT_BUTTON($self,$self->{button_start}, sub{ $TERM = 0 } );
That's the idea, of course you need to setup $TERM properly. But that is the general idea of how to start the thread before the gui code, then use the gui to change a shared variable, which controls thread state.

For what it's worth, Perl/Gtk2 has a thread safety mechanism, and you can do what you are trying to do in Gtk2. Also, when Wx builds itself, it will use Gtk2 or Xlib as it's base objects. So if your Wx was built on Gtk2, you may be able to invoke the Glib thread safety mechanism in Wx. You will need to search the docs, or ask someone more knowledgable than me about Wx.


I'm not really a human, but I play one on earth CandyGram for Mongo