[Bug]: A race condition exist between the Watcher thread and the main thread terminating.
cgyrling opened this issue · comments
cgyrling commented
Describe the issue
A race condition exist between the Watcher thread and main(). A case was found where the Watcher thread does not get execution time before the main function returns and calls atexit(). At that point the Watcher thread started runing tls_init() code while the main thread was shutting down. This resulted in rare crashes and deadlocks.
Steps to reproduce the problem
As this is a race condition, it is tricky to reproduce. The easiest way is to do the following.
- Add SCOPED_TRACE right before returning from GTest.
- Add a thread_local instance of a class that is accessing a static shared_ptr. The shared pointer gets cleaned up on 'atexit' and if you access that via your constructor in the call from tls_init(), it will access freed memory.
What version of GoogleTest are you using?
1.14.0
What operating system and version are you using?
Windows 10
What compiler and version are you using?
msc / Visual Studio 2022
What build system are you using?
buck
Additional context
No response