Boost logo

Boost :

Subject: Re: [boost] [1.44] Beta progress?
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2010-08-06 11:45:51


On 08/06/2010 04:15 PM, Anthony Williams wrote:
> On my linux system that aborts the program with "FATAL: exception not
> rethrown"

The following code produces:

$ ./a.out
Thread started
interrupted
terminate called after throwing an instance of 'std::runtime_error'
  what(): interrupted
Aborted

#include <cxxabi.h>
#include <cstdlib>
#include <iostream>
#include <pthread.h>
#include <stdexcept>

static pthread_cond_t condition = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

static void *foo (void *)
{
  try {
    std::cout << "Thread started" << std::endl;
    ::pthread_mutex_lock(&mutex);
    ::pthread_cond_wait (&condition, &mutex);
  }
  catch (abi::__forced_unwind&) {
    std::cout << "interrupted" << std::endl;
    throw std::runtime_error("interrupted");
   }
  catch (...) {
    std::cout << "..." << std::endl;
    throw;
  }
}

int main (int argc, char** argv)
{
  pthread_t thread_foo;
  ::pthread_create (&thread_foo, NULL, foo, NULL);

  sleep (1);

  ::pthread_cancel (thread_foo);
  ::pthread_join (thread_foo, NULL);
}

Regards
Gaetano Mendola


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk