5 May
2014
5 May
'14
7:31 p.m.
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.