Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 6.7.1 and thread storage duration
#1
Is Rule 6.7.1 intended to apply to local variables with thread storage duration?  For example:

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.
Reply
#2
We should have said that 'thread_local' is equivalent to 'static' for this rule and indeed for 11.6.1 as well  (All variables should be initialized).

See C++::2017  [basic_start_static] para 2.

A note has been made to update the document accordingly
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)