How to handle long I/O operations



Hello,

I am wondering the best approach to coding for long operations occuring
during a signal callback. 

Basically, the GUI I am writing may make a single synchronous shared
library call that may be disk intensive and may take several minutes to
complete. In the meantime, I have a progress bar in activity mode that I
am going to update periodically.

I have something that works currently but wonder if this is overkill.

I do a gtk_timeout_add() to add a function that gets called to
periodically update the progress bar.

I then call pthread_create() to create a thread that executes the disk
intensive function. I pass the thread the tag for the timeout function
so that when the disk intensive call completes, it removes the timeout
to stop the progress bar before the thread exits.

I then return to the main loop which deals with calling the timeout
every so often.

This all works just fine but my executable now is dependent on pthreads
for just this one callback.

Are there better alternatives that won't add a requirement on another
library. An example of this would be great. fork() did not work as I was
not able to remove the timeout function since the child process had its
own process space. I haven't tried clone().

I like the clean approach of the threaded implementation but as I said
before, it is overkill with respect to requiring a dependency on yet
another library. 


regards,

Luciano Chavez
EVMS GUI developer
http://www.sf.net/projects/evms





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]