Commit 291e9dd
authored
fix: wait until AutomaticallyCreatedBackgroundThreads start (#8452)
Don't return from the `AutomaticallyCreatedBackgroundThreads` ctor until we
know that each thread functor has been invoked.
Some users hold their client objects, which own `BackgroundThreads` objects,
in such a way that the client is not destroyed during process shutdown, and
therefore that its background threads are not joined. This means that it
is possible for a `std::thread` to be running but still within the standard
library (i.e., not yet in the user functor) while global objects are being
destroyed.
In the case at hand, the standard library was in the process of setting up
thread-specific data via `pthread_setspecific()`, when its key appears to
have disappeared from underneath it, resulting in MemorySanitizer errors.
This probably isn't the only shutdown race waiting to bite us, but it is one
we've seen in practice.1 parent 3cdd834 commit 291e9dd
1 file changed
+10
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| |||
0 commit comments