Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > a concurrent pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9531 of 9828
Post > Topic >>

a concurrent programming abstraction

by restor <akrzemi1@[EMAIL PROTECTED] > Apr 22, 2008 at 03:22 PM

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! ]
 




 3 Posts in Topic:
a concurrent programming abstraction
restor <akrzemi1@[EMAI  2008-04-22 15:22:52 
Re: a concurrent programming abstraction
Tony Delroy <tony_in_d  2008-04-22 22:27:27 
Re: a concurrent programming abstraction
Lance Diduck <lancedid  2008-04-23 13:27:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:36:15 CDT 2008.