Make cgf_diagnostics::teardown() a no-op instead of resetting the instance#339
Open
GagaLP wants to merge 1 commit into
Open
Make cgf_diagnostics::teardown() a no-op instead of resetting the instance#339GagaLP wants to merge 1 commit into
GagaLP wants to merge 1 commit into
Conversation
|
Check-perf-impact results: (ae6918621b46271c2f10d6eb978fe95d) ❓ No new benchmark data submitted. ❓ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After a while of debugging a strange
Access Violationerror on Windows during teardown of Celerity, I traced it back tocgf_diagnostics::teardown().cgf_diagnosticsstores its singleton in athread_local std::unique_ptr.teardown()is called fromruntime::impl's shutdown path, which runs whenruntime::s_instance(a plainstaticmember) is destroyed, and if the application never callsruntime::shutdown()explicitly, that happens as part of normal static-object teardown aftermain()returns.The C++ standard leaves the relative order of static-object destruction and
thread_localdestruction for the main thread undefined. On Windows, these use separate mechanisms (the CRT's atexit/exit machinery vs. TLS callbacks), and in this case thethread_localstorage for the main thread was already gone by the timeteardown()calledm_instance.reset()on it, resulting in access to unavailable memory.Removing the
m_instance.reset()call fixes this issue while keeping the logic the same: the whole point of using a smart pointer here is that its cleanup is already handled automatically, so an explicit reset inteardown()is redundant.