Boost logo

Boost :

Subject: Re: [boost] Boost sprint: #3407 boost::call_once not re-entrant(atleast in win32)
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-11-23 11:43:59


On Mon, Nov 23, 2009 at 10:25 AM, Peter Dimov <pdimov_at_[hidden]> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk