Subject: Re: [boost] Boost sprint: #3407 boost::call_once not re-entrant(atleast in win32)
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-11-23 10:19:28
Francois Barel wrote:
> Anthony Williams wrote:
>> The current implementation handles exceptions "properly" in the sense
>> that if the once function exits with an exception then it is not
>> marked as called and another thread (possibly one of those waiting)
>> will call it.
> Does this mean the function will be called again? Isn't that
> disturbing for something named "call_once"?
No, it's the correct behavior. The function is not considered "called"
unless it returns. The use case for call_once is to perform initialization
of a resource to be used. An exception means that the initialization failed.
> The behavior I would expect instead is: if the function throws an
> exception, (an internal flag is set, and) other "call_once" calls will
> also throw an exception immediately, without calling the function
This is not how pthread_once and local statics work. Both specify that if
the one-time initialization fails (is canceled in the first case, throws in
the second), the initialization is retried the next time it's attempted.
In the first case, specifically, it makes no sense to "rethrow" the
cancelation exception when some other thread calls pthread_once.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk