Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: convert a single thread application to multithread with GUI

by zentara (Archbishop)
on Jul 11, 2007 at 12:51 UTC ( #625999=note: print w/ replies, xml ) Need Help??


in reply to convert a single thread application to multithread with GUI

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


Comment on Re: convert a single thread application to multithread with GUI
Re^2: convert a single thread application to multithread with GUI
by ultibuzz (Monk) on Jul 11, 2007 at 13:08 UTC

    thx for your tips, and yes i just seek some basic advice at the moment, so there is no code yet.
    either i want to use Tk or Gtk.

    kd ultibuzz

      Here's a simple Tk idea. (I use END: blocks in the thread to emphasize what is happening, but simple returns will suffice)

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum

        thats an awsome exaple, now i know how to make a cmd like text scrollbox ;)
        also the thread reuse thing is now a bit clearer
        thx for the nice example and i hope it will push me in the right direction

        kd ultibuzz

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://625999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-11-28 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (196 votes), past polls