From f15d001ba0735a2438fe33ea6bc6d4410cccd84a Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Tue, 4 Oct 2016 16:43:47 +0100 Subject: [PATCH] Added note about detached threads racing with global destructors --- CppCoreGuidelines.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 1e0890a..5466995 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -12287,6 +12287,12 @@ By "bad" we mean that a `thread` may use a pointer after the pointed-to object i The fact that `thread`s run concurrently doesn't affect the lifetime or ownership issues here; these `thread`s can be seen as just a function object called from `some_fct`. +##### Note + +Even objects with static storage duration can be problematic if used from detached threads: if the +thread continues until the end of the program, it might be running concurrently with the destruction +of objects with static storage duration, and thus accesses to such objects might race. + ##### Enforcement In general, it is undecidable whether a `detach()` is executed for a `thread`, but simple common cases are easily detected.