10-09-2024, 06:40 PM
Is Rule 6.7.1 intended to apply to local variables with thread storage duration? For example:
While the rule specifically references "static storage duration" it is not clear what the intended impact of this rule is with respect to "thread storage duration" variables. While local variables with thread storage duration do not suffer the same intrinsically thread-unsafe characteristics as those with static storage duration, the provided Rationale still applies. In particular, they decrease comprehensibility, introduce temporal coupling, and can result in (reentrant) data races.
Code:
typedef int int32_t;
void foo() {
static int32_t var1{0}; // Non-compliant
thread_local int32_t var2{0}; // Compliant ???
/* ... */
}
While the rule specifically references "static storage duration" it is not clear what the intended impact of this rule is with respect to "thread storage duration" variables. While local variables with thread storage duration do not suffer the same intrinsically thread-unsafe characteristics as those with static storage duration, the provided Rationale still applies. In particular, they decrease comprehensibility, introduce temporal coupling, and can result in (reentrant) data races.