
On Mon, Nov 23, 2009 at 10:25 AM, Peter Dimov <pdimov@pdimov.com> wrote:
Gottlob Frege wrote:
But then complete_once() would imply recursion also, so I decided to separate the concepts.
If you look at local statics for guidance [6.7/4 in N3000]:
"If the initialization exits by throwing an exception, the initialization is not complete, so it will be tried again the next time control enters the declaration."
"If control re-enters the declaration recursively while the object is being initialized, the behavior is undefined."
I agree, particularly for local statics. I was just experimenting, and 'concurrently' there was an email here about it, so I tossed out my experiment.
No, it's the correct behavior. The function is not considered "called" unless it returns.
Unfortunately the function obviously was *called*. But I just think this means "call_once" is a slightly inaccurate name. It doesn't mean we should change the implementation. And "call_and_return_once" is a bit much. :-) Again, for me, it was just an experiment. The recursive check, in particular, I considered probably only useful when debugging (my version asserts in debug). In general, call_once and static locals are something of a hobby of mine, as sad as that is (ie I have no life). You might recall (as you were in some of the discussions) usenet posts in the past from me concerning: void f() { static_local<Foo> foo; ... } and void f() { static Once once; if (Once::Sentry sentry = once) { do_stuff_once(); etc(); } // or wait till done more_code(); } Or not recall, as there's lots of posts out there! Anyhow thanks for the opinions on exceptions and recursion. Confirmed my expectations. Tony