
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"?
The suggestion is to optionally have the function marked as called even if an exception is thrown. I don't think this is worthwhile.
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 again. Ideally (for me) the exception would be the one thrown by the function when it was called (i.e. the exception object would be caught and stored during the first "call_once" call, and then thrown again in other "call_once" calls) -- but I could live with other "call_once" calls throwing a system exception (something like "function_threw_exception") instead. I imagine some people will prefer the current behavior (and I guess it has to stay for compatibility's sake anyway), so maybe the two should be available somehow (new flag, policy or new function)? Regards, François