
Roland Schwarz <roland.schwarz@chello.at> 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 -- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk