| Submitter | Jonathan Wakely |
|---|---|
| Date | Nov. 7, 2011, 10:26 p.m. |
| Message ID | <CAH6eHdSqJLgtmMak-UV7DfN=M5+k6=9nQDdUa7vJsdMpnNGvxw@mail.gmail.com> |
| Download | mbox | patch |
| Permalink | /patch/124206/ |
| State | New |
| Headers | show |
Comments
> Fixed like so ... > > * include/std/mutex (call_once): Store closure in __once_functor > as bound function wrapper might not be copyable. > > The fix would be simpler but the lambda can't capture the parameter > pack directly because of PR c++/41933. Unfortunately the non-TLS > std::call_once implementation is quite wasteful, creating a function > wrapper, which is captured by a closure, which is stored in a > std::function. IIRC the std::function has to be kept for backwards > compatibility, otherwise we could just store the closure and a pointer > to a function, like the TLS code but using a mutex to serialize calls. Thanks a lot for the quick fix!
Patch
Index: include/std/mutex =================================================================== --- include/std/mutex (revision 181123) +++ include/std/mutex (working copy) @@ -810,8 +810,9 @@ __once_call = &__once_call_impl<decltype(__bound_functor)>; #else unique_lock<mutex> __functor_lock(__get_once_mutex()); - __once_functor = std::__bind_simple(std::forward<_Callable>(__f), + auto __callable = std::__bind_simple(std::forward<_Callable>(__f), std::forward<_Args>(__args)...); + __once_functor = [&]() { __callable(); }; __set_once_functor_lock_ptr(&__functor_lock); #endif