c++ - does the standard mandate destruction of thread_local variable on computing time of the dying thread? - Stack Overflow
- c - Solaris 10 make Error code 1 Fatal Error when trying to build python 2.7.16 - Stack Overflow 推荐度:
- javascript - How to dismiss a phonegap notification programmatically - Stack Overflow 推荐度:
- javascript - Get the JSON objects that are not present in another array - Stack Overflow 推荐度:
- javascript - VS 2015 Angular 2 import modules cannot be resolved - Stack Overflow 推荐度:
- javascript - Type 'undefined' is not assignable to type 'menuItemProps[]' - Stack Overflow 推荐度:
- 相关推荐
Afaik a (static) thread local variable is destroyed (immediately ?) when the associated thread terminates.
Does the standard mandates that the destruction happens on computing time of the dying thread? In other words, is the thread id inside of such an destructor the tid of the associated thread and thread_local variables are gone before final death of the thread?
While writing this, I ask myself if even construction of thread_local objects are always mandatory happen via the associated thread?
Afaik a (static) thread local variable is destroyed (immediately ?) when the associated thread terminates.
Does the standard mandates that the destruction happens on computing time of the dying thread? In other words, is the thread id inside of such an destructor the tid of the associated thread and thread_local variables are gone before final death of the thread?
While writing this, I ask myself if even construction of thread_local objects are always mandatory happen via the associated thread?
Share Improve this question asked yesterday albertalbert 4812 silver badges10 bronze badges1 Answer
Reset to default 2[basic.start.dynamic]/7 It is implementation-defined whether the dynamic initialization of a non-block non-inline variable with thread storage duration is sequenced before the first statement of the initial function of a thread or is deferred. If it is deferred, the initialization associated with the entity for thread t is sequenced before the first non-initialization odr-use by t of any non-inline variable with thread storage duration defined in the same translation unit as the variable to be initialized.
Now, "sequenced before" is defined ([intro.execution]/8) as "an asymmetric, transitive, pair-wise relation between evaluations executed by a single thread". Emphasis mine. I think this implies that the initialization must be performed by the same thread as the initial function, or else one can't be sequenced before the other.
There isn't a similar "sequenced before" wording for thread termination. The standard only says that thread-local objects are destroyed "as a result of" thread termination, whatever that means:
[basic.start.term]/2 Constructed objects with thread storage duration within a given thread are destroyed as a result of returning from the initial function of that thread and as a result of that thread calling
std::exit
.
The standard does say that the destruction of several thread-local objects is sequenced relative to each other; so at least, all such objects must be destroyed on the same thread:
[basic.start.term]/3 ... If the completion of the constructor or dynamic initialization of an object with thread storage duration is sequenced before that of another, the completion of the destructor of the second is sequenced before the initiation of the destructor of the first...
I think the intent is that thread-local objects are destroyed by the same thread that initialized them; and it's hard to imagine an implementation doing anything else.
- 安卓之父曾遭三星高管嘲笑:你们喝醉了吗
- 分析称苹果本届WWDC将侧重软件 不会发布iPhone 5
- schema - TALLY XML API ISSUE - Stack Overflow
- android - Segmentation Fault at start up of Maui App - Stack Overflow
- file permissions - UNITY An error occurred while resolving packages: EPERM: operation not permitted, mkdir - Stack Overflow
- eslint - How to have 2 no-restricted-globals rules with different severity? - Stack Overflow
- node.js - Cors errors S3 Upload node - Stack Overflow
- css - How to bring the curved tail behind the img - Stack Overflow
- google colaboratory - Load a Kaggle dataset into Colab notebook without extracting it - Stack Overflow
- powerbi - Keep Date Filter Active After Hiding Matrix-Based Calendar in Report Viewer - Stack Overflow
- html - Vertical Alignment of text inside a container, that is nested within another container - Stack Overflow
- swift - SwiftUI ScrollView not scrolling with DragGesture inside a ForEach Item - Stack Overflow
- How to list ALL Zoom cloud recordings? - Stack Overflow
- dolphindb - Whitepaper error: “cannot recognize the token b” - Stack Overflow
- artificial intelligence - ImportError in Python when using the phi library - Stack Overflow
- typescript - angular signal is not recomputing - Stack Overflow
- window - Strawberry Perl doesn't include Win32::shortcut? - Stack Overflow