2015-09-05 21:31 GMT+02:00 Hartmut Kaiser
what does that mean 'maintained by the runtime'? void bar( ptr_scheduler_thread_local_var) { printf("%p\n", ptr_scheduler_thread_local_var); suspend_and_migrate_fiber(); }
void foo() { while ( true) { bar( return_ptr_of_scheduler_thread_local_var() ); ... } } in this example b) accesses a) (TLS of scheduler) prints in to stdout suspends active fiber and migrates it to another thread after resumption the address of the TLS-scheduler is printed out ... how does your code look like after compiler optimization?!
a) is safe as all threads sharing the same scheduler store the same reference (fibers can be moved only inside that scheduler) b) is safe as the runtime sets the reference to the fiber it is about to run in TLS and resets it right after the fiber returned.
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?