brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 93d403c Raw
30 lines · plain
1.. title:: clang-tidy - bugprone-dynamic-static-initializers2 3bugprone-dynamic-static-initializers4====================================5 6Finds instances of static variables that are dynamically initialized7in header files.8 9This can pose problems in certain multithreaded contexts. For example,10when disabling compiler generated synchronization instructions for11static variables initialized at runtime (e.g. by ``-fno-threadsafe-statics``),12even if a particular project takes the necessary precautions to prevent race13conditions during initialization by providing their own synchronization, header14files included from other projects may not. Therefore, such a check is helpful15for ensuring that disabling compiler generated synchronization for static16variable initialization will not cause problems.17 18Consider the following code:19 20.. code-block:: c21 22  int foo() {23    static int k = bar();24    return k;25  }26 27When synchronization of static initialization is disabled, if two threads both28call `foo` for the first time, there is the possibility that `k` will be double29initialized, creating a race condition.30