Boost logo

Boost :

From: Hillel Y. Sims (hsims_at_[hidden])
Date: 2002-08-13 12:45:20

"William E. Kempf" <williamkempf_at_[hidden]> wrote in message
> 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
> 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)
       cout << "the answer is: " << sharedData.answer << endl;

void* threadfunc(void*)
  Lock lock(mutex);
  sharedData.answer = 42;
  sharedData.ready = true;
  if (random() % 2)
     throw catch_me_if_you_can();
  return 0;


Hillel Y. Sims
FactSet Research Systems
hsims AT

Boost list run by bdawes at, gregod at, cpdaniel at, john at