Are inline functions in C/C++ a way to make them thread-safe?

Nope, you are wrong. For a static variable, whether it is inlined or not, there is only actually one instance. Inlined functions have no effect on thread safety, one way or the other.


When you declare a function as inline, it is merely a hint to the compiler. Static variables have a clear definition in the language. If the compiler does inline the function, it is still obligated to keep the static variables shared between all instances of the function. Therefore, they will remain global and have to be protected in a MT environment.

As to the local variables, unless they are used outside of the function, they are thread safe regardless of the function being inlined or not.


Each thread gets its own copy of the local objects hence there can not be any threading related issues with them whether you make it inline or not.

But if you are accessing a static or a member variable of the class, all the issues related to the multithreading (corrupting the variable, lost updation...) will still be there irrespective of whether it is inline or not.