Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] Boost.Fiber mini-review September 4-13
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2015-09-06 08:27:39


On 09/06/2015 06:30 AM, Oliver Kowalke wrote:
> 2015-09-05 22:04 GMT+02:00 Hartmut Kaiser <hartmut.kaiser_at_[hidden]
> <mailto:hartmut.kaiser_at_[hidden]>>:
>
>
> > but I was asking for the code snipped which accesses TLS variable - if all
> > threads share the same scheduler why has it to be stored in TLS?
> > a slight modification of my example above - replace
> > retrn_ptr_of_scheduler_thread_lcoal_var() by return_ptr_to_active_fiber()
> > I assume that as you mentioned in b) that the active fiber is stored in
> > TLS - the exmaple code prints out the address of the current active fiber
> > how does the code look like after compiler optimization?
>
> I don't know. We have never ran into any problems related to this.
>
>
> I did a short look at the souces from HPX - please correct me if my
> assumptions are false:
>
> - HPX does not support C++11, so thread_local is not available - instead
> you implemented thread_specific_ptr

It does support C++11 and C++14. thread_specific_ptr is an artifact from
the past but still perfectly conformant in C++11/14.

>
> - thread_specific_ptr has an private member - static __thread T * t - so
> thread_specific_ptr is the TLS container

correct.

>
> - coroutine_impl has a private member - static thread_specific_ptr<
> self_type > self_ which is used to access the 'active fiber/coroutine' via
> static member function - static self_type * get_self()

correct.

>
> - coroutine_impl::operator() executes the function/code passed to
> coroutine_impl
>
> - the implementation of coroutine::operator() looks like this (in short):
>
> void operator() {
> do {
> self_type * old_self = coroutine_impl::get_self();
> self_type self( this, old_self);
> reset_self_on_exit( & self, old_self);
>
> fun(); // execute function
> } while ( state == running);
> }
>
> I the compiler optimizes the code - self_type * old_self =
> coroutine_impl::get_self(); - will likely be moved out of the do-loop.

nope it won't. see my other post for an explanation of this.

>
> void operator() {
> self_type * old_self = coroutine_impl::get_self();
> do {
> self_type self( this, old_self);
> reset_self_on_exit( & self, old_self);
>
> fun(); // execute function
> } while ( state == running);
> }
>
> This happens probably in other places of HPX too - the question is why
> you never ran into any problems.

because we use the value, not the address of the TLS variable, which is
of course constant.

>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net