Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

convert a single thread application to multithread with GUI

by ultibuzz (Monk)
on Jul 11, 2007 at 11:46 UTC ( #625988=perlquestion: print w/ replies, xml ) Need Help??
ultibuzz has asked for the wisdom of the Perl Monks concerning the following question:

I have a programm that process files one by one,now i want to change it into a multithreaded programm so it will process more files in the same time.

it will be a gui program,so the main process will control the gui , buttons and the log window.

thoughts & problems
1. all files that are in procces right now , stored in 1 array.
2. avoid sametime acces of that array,log is no problem because of system and perl buffering on outputs.
3. several exit modes: stop,abort , exit , immediate exit.
stop = stop processing of new files but finish all in progress files
abort = same as stop but interrupt in progress files and roll back all changes and move in progress files back to need_to_process
exit = same like stop but quit the program
immediate exit = same like abort but quit program

4. logging, star and end of processing shoud be written to logfile,and problems and oks also.
there will be and log parser that checks if every file has a start and end in log if not delete file changes from db and move problem file back to need_to_process.
only will be uses on first start of program or manually after critical aborts(system off, or something else)

5. the logwindow shoud scroll down so it always show the latest infos.
6. the programm will run forever. so it need to be coded nicly in var handling
7. if they are no files to process the programm will wait 5 mins and then look again for files.
8. maximum threads shoud be 6 including main thread so 5 workers.

 

thats what is in my mind so far, any suggestions or points that i shoud think about or to avoid ?

kd

ultibuzz

Comment on convert a single thread application to multithread with GUI
Re: convert a single thread application to multithread with GUI
by zentara (Archbishop) on Jul 11, 2007 at 12:51 UTC
    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

      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
Re: convert a single thread application to multithread with GUI
by ultibuzz (Monk) on Jul 31, 2007 at 09:53 UTC

    thx for the great help, but i need to park this project for a bit
    on my desk landed something more importent, but i definatly will come abck to this

    kd ultibuzz

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-10-22 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls