craigdillabaugh
29th April 2009, 19:39
Hi,
I am just learning how to work with threads and I wanted to know if someone could help me with suggestions as to how I might go about solving the following problem. I don't need code (although it would be great), just some ideas on how to design my application.
I have an application that needs to download a large number of large files from an FTP server and then perform some processing on those files. Since downloading will take quite a while I want to start processing files as their downloads complete. To further complicate things the 'processing' is being done by an external program that I will likely use by calling the C system() function.
In reading the documentation for QSemaphore I thought I could modify the example program at:
http://doc.trolltech.com/4.5/threads-semaphores.html
for my needs.
I would have a Producer class which downloads the file and a Conumser class which processes the file. My 'buffer' will simply be a list of file names (I use QFtp to get a listing beforehand) I want the Producer to acquire a filename and release it once completed. My Consumer would then acquire the filenames as they were released.
My problems are:
1. I use QFtp to download my files. If I start a download (or series of downloads) from Producer::run() how can I pause that thread until I get the Finished signal back from my QFtp notifying me that a download has been completed, so that I can then release a resource to the Consumer thread and start my next QFtp instance.
2. In my Consumer thread I would like to know when the process spawned by my 'system()' calls finishes :crying:. My idea was to modify the program being called so that it outputs a temporary file when it finishes (I have access to the code), and occassionally check for this file as notification that the system call is done. Is there a better way to do this?
Thank you for any suggestions.
Craig
2.
I am just learning how to work with threads and I wanted to know if someone could help me with suggestions as to how I might go about solving the following problem. I don't need code (although it would be great), just some ideas on how to design my application.
I have an application that needs to download a large number of large files from an FTP server and then perform some processing on those files. Since downloading will take quite a while I want to start processing files as their downloads complete. To further complicate things the 'processing' is being done by an external program that I will likely use by calling the C system() function.
In reading the documentation for QSemaphore I thought I could modify the example program at:
http://doc.trolltech.com/4.5/threads-semaphores.html
for my needs.
I would have a Producer class which downloads the file and a Conumser class which processes the file. My 'buffer' will simply be a list of file names (I use QFtp to get a listing beforehand) I want the Producer to acquire a filename and release it once completed. My Consumer would then acquire the filenames as they were released.
My problems are:
1. I use QFtp to download my files. If I start a download (or series of downloads) from Producer::run() how can I pause that thread until I get the Finished signal back from my QFtp notifying me that a download has been completed, so that I can then release a resource to the Consumer thread and start my next QFtp instance.
2. In my Consumer thread I would like to know when the process spawned by my 'system()' calls finishes :crying:. My idea was to modify the program being called so that it outputs a temporary file when it finishes (I have access to the code), and occassionally check for this file as notification that the system call is done. Is there a better way to do this?
Thank you for any suggestions.
Craig
2.