From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-08-03 03:20:55
Jonathan Turkanis wrote:
> Pavel Vozenilek wrote:
> > "Jason Hise" wrote:
> >>> http://www.boost.org/doc/html/call_once.html?
> >> Why does it require that the function which is called once not be
> >> allowed to throw? I am not sure that I can meet this requirement,
> >> as I may need to dynamically allocate memory.
> > Possibly because of internal implementation.
> I think it's a pthreads requirement.
Pthreads knows nothing about exceptions, so it can't strictly require
that one isn't thrown :-)
I assume it's because an exception that causes an early exit from
pthread_once could prevent the "once flag" being set, which would allow
the function to be run more than once. This is actually opposite to the
POSIX spec for pthread_once, which explicitly says that if the thread is
cancelled while running the function then it is as though pthread_once
had never been called i.e. the function *can* run more than once. Thread
cancellation is supposed to behave like an exception, so the Boost
requirement is arguably too strict. It's probably just to be safe,
since interaction between exceptions and thread cancellation is a very
open issue and is far from portable.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk