我们正在和我的朋友讨论函数和多线程。示例代码为:互斥和内联函数
void SomeClass::Foo()
{
std::lock_guard<std::mutex> lock(mMutexObj);
statement1;
statement2;
statement3;
}
所以,我们知道,有时候编译器内联在需要的地方的功能。是否有可能在这种情况下:编译器内联的Foo
功能,所有的3个语句运行,lock_guard
因为范围并不在这里结束不工作,并呼吁没有析构函数:
// Inlined operations
std::lock_guard<std::mutex> lock(mMutexObj);
statement1;
statement2;
statement3;
// Global scope, where function was inlined continues here...
global statement1;
global statement2;
...;
这可能吗?该编译器将内联该函数的百分比是多少,或者我不明白内联函数的范围?
允许内部更改范围吗?我总是想象它会在任何被复制的周围添加'{'和'} ... – 2013-08-06 21:34:29
@ebyrob我认为改变范围会造成严重破坏。使用#defines会做到这一点。我认为内联函数的一个原因是为了避免#defines引起的问题 – maditya