From: Anthony Williams (anthwil_at_[hidden])
Date: 2002-08-07 09:25:51
> From: Peter Dimov [mailto:pdimov_at_[hidden]]
> Sent: 07 August 2002 13:56
> From: "Anthony Williams" <anthwil_at_[hidden]>
> > > Is this possible? Without language/memory architecture
> > > support, I mean.
> > See my other post for Win32Mutex and POSIXMutex skeletons
> that just have a
> > default constructor.
> > My point is that you can have thread-safe lazy dynamic
> > works for static objects without causing init-order
> problems, if you use
> > appropriate primitives for each platform. On POSIX,
> pthread_once provides
> > such a mechanism;
> pthread_once takes a single void (*) (), there is no way to
> pass arguments,
> like the address of the mutex being initialized.
Ouch. I had forgotten that :-(
OK, we need a one-time-only initialization mechanism, such as the following
(adjusted for exception safety, and proper destruction of the std::set);
void initMutexOnce(pthread_mutex_t* theMutex)
// ensure support set/rwlock initialized
// we're reading the set
// check whether or not mutex is initialized
// mutex not initialized, so change from reader to writer
// and initialize mutex
Admittedly, you can then only initialize one mutex at a time, but it should
work, and checking for already-initialized mutexes shouldn't be too slow.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk