GMock crashes on exit (WatcherThreadFunc) when used from third-party test harness #4729
Unanswered
SiriusTR
asked this question in
Community Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm using GMock from a third-party unit test harness, and I started noticing these tests were occasionally generating crashes after they finished running. Recently they became more consistent, which enabled me to figure out the culprit; the tests are in a .DLL, and at the end of execution, the DLL is unloaded, but there is a GMock-created watcher thread (
testing::internal::ThreadLocalRegistryImpl::WatcherThreadFunc
) that is still running.This thread appears to be created from the following stack:
Looking at the implementation of
ThreadLocal
, I see the following comments:OK, great - so it looks like the key is making sure ThreadLocal is cleaned up properly. Unfortunately, this test harness doesn't have a main() function I can edit (it works a lot like CppUnitTestFramework, as illustrated by this StackOverflow post - it looks like I'm not the first one to encounter the crash either). What's the appropriate way to ensure ThreadLocal is correctly wound down in this case? I note there is a place to put post-test cleanup code, but it doesn't run on the initial thread.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions