Re: [boost] Enhanced call_once()
by William E. Kempf other posts by this author
Aug 9 2002 1:39PM messages near this date
Re: [boost] Enhanced call_once()
|
Re: [boost] Enhanced call_once()
----- Original Message -----
From: "Andrew J Bromage" <ajb@[...].net>
> On Thu, Aug 08, 2002 at 09:35:19AM -0500, William E. Kempf wrote:
> > What's being synchronized is the call to the routine,
> > and the important thing is that any thread that attempts to
> > call this either actually calls the routine if it was the first, or
blocks
> > until the routine has been called and returns.
>
> You've mentioned two things that may happen. In fact there are three,
> and the one you left out is precisely the one that the DCL idiom is
> meant to optimise, namely, the case that the single routine call has
> already completed and therefore does not need to be called again. In
> this case, the caller should not (in theory) need to block.
>
> The problem is the "in theory" part, of course.
No, the calling thread must always block *while the once routine is
running*. The DCL pattern does insure this by locking a mutex when the flag
is found to be unset. Where it fails is when the flag is set, but other
memory modified in the once routine has not yet been made visible to the
calling thread.
The DCL doesn't try to avoid blocking when the routine is running, it only
tries to avoid an expensive lock call when the routine has already been run.
Bill Kempf
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Andrew J Bromage
Peter Dimov
Andrew J Bromage
William E. Kempf
Andrew J Bromage
William E. Kempf
Alexander Terekhov
Pete Becker
Andrew J Bromage
Peter Dimov
Andrew J Bromage
William E. Kempf
Andrew J Bromage
William E. Kempf
Rene Rivera
William E. Kempf
Andrew J Bromage
Jason Stewart
Andrew J Bromage
Andrew J Bromage
Rob Stewart
William E. Kempf
William E. Kempf
Alexander Terekhov
Peter Dimov
Peter Dimov
Pete Becker
William E. Kempf
William E. Kempf
Pete Becker
|