In my application I need to sort out a rather large array, which, as it turns out, is a standard problem, for example std::sort.
Being located in a GUI application, I would like to give some kind of answer to the sorting progress. My first attempt is to figure out the approximate number of comparisons needed ( n*log2(n)for std::sort), and then just count them in the comparison function passed to std::sort. This works quite well.
The sorting algorithm runs in a separate thread to support a graphical interface. It associates its progress with a graphical interface using Qt signals or some similar thread protection mechanism.
However, I would also like the sort operation to abort. That is, the user is provided with a button or something similar to interrupt the entire operation. At the moment, I see only two options:
- Proactive thread termination (
pthread_canceletc.) - rewrite the sorting algorithm and insert explicit undo points.
Given the cancellation of the stream, as a last resort and refusing to rewrite standard library algorithms, I hold the wolf by the ears.
source
share