Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-13 13:54:39


> Hmm, I'm not sure about static, since we are bound to get caught up in
> scoping issues between translation units again...

*local* static.. e.g.

static pthread_once_t s_once_control = PTHREAD_ONCE_INIT;
static atexit_impl_singleton* atexit_impl_singleton::s_instance = 0;

static void s_create_mysingleton()
{
  // ctor sets the atexit_impl_singleton::s_instance pointer/
  // dtor resets the pointer after calling all registered
  // handlers using some while !coll.empty loop processing
  // elements in LIFO order
  static
    atexit_impl_singleton
      the_atexit_impl_singleton();
}

void my_atexit( .... )
{
  pthread_once( &s_once_control,s_create_mysingleton );
  if ( 0 == atexit_impl_singleton::s_instance )
  { /* error handling */ }
  // internally synchronized method
  atexit_impl_singleton::s_instance->register( .... );
}

or something similar but simply with statically initialized
mutex.

regards,
alexander.


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