Hi,
This may not be the best place to post this question, but I didn't
know who to ask, so sorry if this is a bit off topic.
I have the following algorithm, that I want to execute in a separate
thread, so that I do not block the main one:
void findBest()
{
for ( Element elem : collection ) // foreach
{
Score score = ComputeScoreIn25minutes( elem );
if ( score > bestScore )
{
bestScore = score;
bestElem = elem;
// iterruption point here
}
}
}
I could use a future<> abstraction as described in N2094, N2185,
N2276, but I do not really have to run my algorithm to an end. I would
like to be able to obtain the best element found so far rather than
wait till the algorithm computes score for the last element in the
collection.
Thus, I would imagine starting my algorithm similarly to how a future
is created:
QFuture<elem> qfuture = run( ... );
Now, calling qfuture's default operation would interrupt the thread
rather than wait until the thread finishes.
I wonder if anyone here have ever thought of something similar. If it
is already implemented. If it has a name. Or if it is possible to
implement such an abstraction, that would not be too intrusive to
function 'findBest' from my example.
I would appreciate any help,
&rzej
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|