Re: MT Design Question
"Scott Meyers" <NeverRead@aristeia.com> wrote in message
news:i52d5k$p1q$1@news.albasani.net...
Chris M. Thomasson wrote:
Are you in control of creating the search functions?
Yes.
BTW, you seem to be revealing more and more "details/requirements"
about/for the problem. Is this a real problem that you are stuck on, or
an "academic" question?
It's academic. I'm trying to figure out what a general solution to this
kind of problem would look like so that I can try to map it to what C++0x
gives me.
Can the graph mutate while readers are performing searches on it?
No. I'm only interested in how to organize the communication between the
threads doing the searching and the thread needing the result of the
search.
I solved this communication under the impression that all searches would
either find an item, or fail to find an item. NOT, throw an exception for
some other reason:
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/9ca81bcf32799d75
Ouch! Well, I could easily return simple integer error codes in the
CAS'able result contained within the `struct complete' data-structure.
Cross-thread exceptions seem to make things more complex. If you spawn 3
futures, and 2 of them throw, where do all of those exceptions get caught
at?
<pseudo-code>
__________________________________________________________
static unsigned g_exceptions = 0;
try
{
std::future f1 = spawn_task(...);
std::future f2 = spawn_task(...);
std::future f3 = spawn_task(...);
// wait for infinity...
Sleep(INFINITE);
}
catch (future_exception const& e)
{
++g_exceptions;
cout << "caught " << g_exceptions << " exception(s)" << endl;
}
__________________________________________________________
If `f2' and `f3' throw, should the output be:
caught 1 exception(s)
caught 2 exception(s)
? I am confused!