Can static block statistics destructors be called multiple times?

I just read this article about the real reasons for the current implementation boost::mutexand noticed the following phrase:

Static block statistics have an additional problem with the potential race "first time" condition, which can cause the destructor to run several times on popular compilers, which is undefined behavior - compilers often use the atexit call equivalent to ensure that destruction occurs in the reverse order of construction and initialization race, which can cause the constructor to be run twice, can also cause the destructor to be registered twice

It's true? Should I really check if there is another thread inside this destructor object through atomic operations or something like this? Do I have to do this even in C ++ 11 - C ++ 14? Since, as far as I know, "a constructor for the same local object with a static storage duration can be called from several threads simultaneously" with C ++ 11 - this requires that other threads wait for the constructor to complete. I'm right?

+4
source share
1 answer

It looks like this article was written before C ++ 11, it says, among other things:

[...] the next version of the C ++ standard, which should be released in 2009. [...]

pre ++ 11, , , pre ++ 11.

++ 11 ++ 11 6.7 ( ):

(8.5) (3.7.1) (3.7.2) . [...] , ; . , , , . , , . [...]

Pre ++ 11 , . pre ++ 11 post ++ , !.

+2

Source: https://habr.com/ru/post/1615719/


All Articles