From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2006-10-06 10:00:49
Roland Schwarz <roland.schwarz_at_[hidden]> writes:
>> Your code demonstrates how we could provide the same facility with pthreads,
>> as an extension to call_once. Incidentally, whilst we're thinking about this,
>> the POSIX spec says:
>> "The behavior of pthread_once() is undefined if once_control has automatic
>> storage duration or is not initialized by PTHREAD_ONCE_INIT."
>> So we need to document this restriction on the use of boost::once_flag, unless
>> you can find a way round it. This restriction doesn't apply on Windows, at
>> least not with my implementation.
> On the second reading I am not any more sure which "restriction" you are
> talking about for Windows:
> 1) may not have automatic storage duration
> 2) must be explicitly initialized by PTHREAD_ONCE_INIT
Sorry, I didn't make it clear. It is the automatic storage duration
restriction which is not present on Windows.
It's also hard to use a pthread_once_t as a class member, since you can't be
guaranteed to use PTHREAD_ONCE_INIT in the member-init-list (e.g. if it's an
aggregate initializer), and you're not allowed to leave it uninitialized, and
initialize it later. You could only use it in a class which is itself an
aggregate, with an appropriate aggregate initializer.
-- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk