[threads] Problem with lambda and tls
Hello, I have a problem when I use lambda in lambda and I want to obtain thread local storage. Here is simple example: auto late_connect = wakeup_signal_notify_to_connect.connect([this](){ auto* alias_to_this = this; this->OnInvokeUpdate(); //here I can obtain thread local storage from boost auto wakeup = wakeup_signal_ptr->connect([alias_to_this]() { alias_to_this->OnInvokeUpdate(); //here I cannot obtain thread local storage from boost } });}); Between first and second of invoke OnInvokeUpdate function there was no destructor call. Someone have idei why ? If I don't use alias for this in capture list there is the same effet. Best regards
On 10.07.2015 14:54, Fu ji wrote:
Hello, I have a problem when I use lambda in lambda and I want to obtain thread local storage. Here is simple example:
auto late_connect = wakeup_signal_notify_to_connect.connect([this](){ auto* alias_to_this = this;
this->OnInvokeUpdate(); //here I can obtain thread local storage from boost
auto wakeup = wakeup_signal_ptr->connect([alias_to_this]() { alias_to_this->OnInvokeUpdate(); //here I cannot obtain thread local storage from boost } });});
Between first and second of invoke OnInvokeUpdate function there was no destructor call. Someone have idei why ? If I don't use alias for this in capture list there is the same effet.
My guess is that you have these lambdas called in different threads.
That's right I replace windows specific api to something cross-platform and
in win there was something like WaitForMultipleEvents check in loop so
there was only one threadid.
Right now I have lambda called from different thread.
Thanks
2015-07-10 14:07 GMT+02:00 Andrey Semashev
On 10.07.2015 14:54, Fu ji wrote:
Hello, I have a problem when I use lambda in lambda and I want to obtain thread local storage. Here is simple example:
auto late_connect = wakeup_signal_notify_to_connect.connect([this](){ auto* alias_to_this = this;
this->OnInvokeUpdate(); //here I can obtain thread local storage from boost
auto wakeup = wakeup_signal_ptr->connect([alias_to_this]() { alias_to_this->OnInvokeUpdate(); //here I cannot obtain thread local storage from boost } });});
Between first and second of invoke OnInvokeUpdate function there was no destructor call. Someone have idei why ? If I don't use alias for this in capture list there is the same effet.
My guess is that you have these lambdas called in different threads.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Andrey Semashev
-
Fu ji