|Perl: the Markov chain saw|
Re: convert a single thread application to multithread with GUIby zentara (Archbishop)
|on Jul 11, 2007 at 12:51 UTC||Need Help??|
You didn't say which GUI toolkit you want to use, and you show no code. So some general advice is:
1. If you use Tk, you must create all your threads before any Tk is invoked. This usually involves reusing threads, and letting them sleep when not used. You cannot manipulate Tk widgets from the threads, except by signalling through shared variables.
2. If you use Gtk2, you can use it's Glib thread-safe mechanism, and launch threads as you need them, AND manipulate Gtk2 objects from the threads, but Gtk2 is a bit trickier to set up. It is still safer to reuse threads, but you may see if disposible threads work for you. If you detach threads, they are disposible, if you don't detach, then you must join them later.
3. For immediate termination of threads, you need to tell it to return. This is usually done through shared variables.
4. Tons of code examples have been posted, just search here or groups.google search.
For a basic Gtk2 example, with thread-reuse, see Threads-w-Perl/Gtk2 demo </code>
I'm not really a human, but I play one on earth. Cogito ergo sum a bum