How to Avoid Thread-Safety Cost for Functions' static Variables

In this blog post, we&rsquo;ll look at static variables defined in a function scope. We&rsquo;ll see how they are implemented and how to use them. What&rsquo;s more, we&rsquo;ll discuss several cases where we can avoid extra thread-safety cost. Let&rsquo;s start. Introduction As you may know, C++ offers a way to define static variables in a function/block scope: void foo () { static int counter =…