Matthias Kaeppler wrote:
Say copying a huge file, maybe 1GB+, is in progress. The progress will be displayed in a dialog window, as usual. Now the user decides that he wants to stop the copy operation, and clicks a cancel button.
Now what do I do? The only means to terminate a thread that I know of is: 1. Killsignal it (I don't think boost supports it, since it's probably highly platform dependent) 2. Check for a terminate flag once in a while and return from the method once it is set.
But how am I supposed to do the latter? The copy function doesn't return until it's finished right? So I can't check for a condition, because the copy-thread itself is blocked until it's done.
Well, if the 'copy' function does not return until it's completely done, then you won't be able to show progress indicator, right? And in order to show progress indicator, you need to copy files in chunks, so you'll have a natural place to check for the terminate flag. But generally, I think Boost is not the best tool for this task. For example, the KDE IO library allows you to request an io operator (like copy), and recieve progress indicator, and you can cancel the operation. Not to mention that it works with URLs, not just local files. Of course, KDE already has a file manager, but I assume you have your reasons for writing one. - Volodya