Subject: Re: [boost] [thread] Request review of new synchronisation object, boost::permit<>
From: Peter Dimov (lists_at_[hidden])
Date: 2014-05-05 15:31:10
Niall Douglas wrote:
> But you've merely constructed the lambda, not executed it. The compiler is
> surely right to think that without it being executed that result's value
> will be constant?
In the example in the docs, you are passing the lambda to another thread,
which means that you're passing a reference to 'result' to another thread.
So it's no longer local.
> I never claimed you shouldn't be using mutexes AND atomics.
Yes, sure. But with an atomic variable as a predicate, people (even
experienced programmers) do make this sort of mistake every time. And if the
variable isn't atomic, they don't, because they always protect it with the
mutex. Using atomic variables is thus more error prone, not less.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk