From: William E. Kempf (williamkempf_at_[hidden])
Date: 2002-08-09 08:39:15
----- Original Message -----
From: "Andrew J Bromage" <ajb_at_[hidden]>
> 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
> > 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
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk