[Bug middle-end/26461] liveness of thread local references across function calls

andy at miniciv dot com gcc-bugzilla@gcc.gnu.org
Fri Apr 1 09:59:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26461

Andy Robbins <andy at miniciv dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andy at miniciv dot com

--- Comment #12 from Andy Robbins <andy at miniciv dot com> ---
Cross posting to help others who need this feature. From a similar ticket on
LLVM, about adding the /GT flag (which fixes the OP's problem, while being
optional, and MSVC supports this):


[...] The option is /GT as specified in the title, and it is not enabled by
default.

There's one particular use case where this kind of option is really important:
a fiber-based job system, something that has been used in video game
development for multi-core machines.

In a system like this, it's common for one job (occupying a fiber) to be paused
(ie: swapped for another fiber in the thread it is running) while it waits for
some other work to finish, and then be resumed (ie: swapped to) from the next
available worker thread, which will be essentially a random worker thread. The
whole point here is to distribute jobs to all available CPU cores evenly and
automatically, so this TLS situation is inevitable and by design.

Yes, TLS is slower in this use case, but it is the correct behaviour. Not
having the /GT flag means having to manually inspect all code and roll a custom
replacement TLS, which is a considerable effort.

Please reconsider having this option.


Reference: https://llvm.org/bugs/show_bug.cgi?id=19177


More information about the Gcc-bugs mailing list