Skip to content

[Bug]: A race condition exist between the Watcher thread and the main thread terminating. #4493

@cgyrling

Description

@cgyrling

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.

  1. Add SCOPED_TRACE right before returning from GTest.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions