|
Boost : |
From: Hillel Y. Sims (hsims_at_[hidden])
Date: 2002-08-13 12:45:20
"William E. Kempf" <williamkempf_at_[hidden]> wrote in message
news:OE52qXkXriph10Jnoa90000a3bb_at_hotmail.com...
>
> This means terminate_thread()
> instead, which only terminates the current thread and not the application.
> A set_terminate_thread_handler() can be employed to handle this case in
the
> same manner that you'd use for application termination.
Hi Bill, what do you think of the following code?
(please overlook the pseudocode aspect, I'm not completely familiar yet with
the boost.thread syntax..)
Mutex mutex;
Condition cond;
DataObj sharedData;
bool serverRunning = true;
void* threadfunc(void*);
int main()
{
Thread* t = new Thread(&threadfunc);
while (serverRunning) {
...
Lock lock(mutex);
sharedData.ready = false;
sharedData.question = ...;
while (!sharedData.ready)
cond.wait(lock);
cout << "the answer is: " << sharedData.answer << endl;
...
}
thread_join(t);
}
void* threadfunc(void*)
{
Lock lock(mutex);
sharedData.answer = 42;
sharedData.ready = true;
if (random() % 2)
throw catch_me_if_you_can();
cond.signal();
return 0;
}
thanks,
hys
-- Hillel Y. Sims FactSet Research Systems hsims AT factset.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk