we were talking about function and multithreading with my friend. The sample code was:
void SomeClass::Foo()
{
std::lock_guard<std::mutex> lock(mMutexObj);
statement1;
statement2;
statement3;
}
So, we know, that sometimes compiler inlines the functions where it's needed. Is it possible in such case: compiler inlines the Foo
function, all the 3 statements run and lock_guard
doesn't work because scope doesn't end here and no destructor called:
// Inlined operations
std::lock_guard<std::mutex> lock(mMutexObj);
statement1;
statement2;
statement3;
// Global scope, where function was inlined continues here...
global statement1;
global statement2;
...;
Is it possible? What percent that compiler will inline such function or maybe I don't understand right the scope of inlined function?