// stub mutex_t: implement this for your operating system
struct mutex_t
{
void Acquire() {}
void Release() {}
};
struct LockGuard
{
LockGuard(mutex_t& mutex) : _ref(mutex)
{
_ref.Acquire(); // TODO operating system specific
};
~LockGuard()
{
_ref.Release(); // TODO operating system specific
}
private:
LockGuard(const LockGuard&); // or use c++0x ` = delete`
mutex_t& _ref;
};
int main()
{
mutex_t mtx;
{
LockGuard lock(mtx);
// LockGuard copy(lock); // ERROR: constructor private
// lock = LockGuard(mtx);// ERROR: no default assignment operator
}
}
Ly8gc3R1YiBtdXRleF90OiBpbXBsZW1lbnQgdGhpcyBmb3IgeW91ciBvcGVyYXRpbmcgc3lzdGVtCnN0cnVjdCBtdXRleF90IAp7IAogICAgdm9pZCBBY3F1aXJlKCkge30gCiAgICB2b2lkIFJlbGVhc2UoKSB7fSAKfTsKCnN0cnVjdCBMb2NrR3VhcmQKewogICAgIExvY2tHdWFyZChtdXRleF90JiBtdXRleCkgOiBfcmVmKG11dGV4KSAKICAgICB7IAogICAgICAgICBfcmVmLkFjcXVpcmUoKTsgIC8vIFRPRE8gb3BlcmF0aW5nIHN5c3RlbSBzcGVjaWZpYwogICAgIH07CgogICAgIH5Mb2NrR3VhcmQoKSAKICAgICB7IAogICAgICAgICAgX3JlZi5SZWxlYXNlKCk7IC8vIFRPRE8gb3BlcmF0aW5nIHN5c3RlbSBzcGVjaWZpYwogICAgIH0KICAgcHJpdmF0ZToKICAgICBMb2NrR3VhcmQoY29uc3QgTG9ja0d1YXJkJik7IC8vIG9yIHVzZSBjKysweCBgID0gZGVsZXRlYAoKICAgICBtdXRleF90JiBfcmVmOwp9OwoKaW50IG1haW4oKQp7CiAgICBtdXRleF90IG10eDsKCiAgICB7CiAgICAgICAgTG9ja0d1YXJkIGxvY2sobXR4KTsKICAgICAgICAvLyBMb2NrR3VhcmQgY29weShsb2NrKTsgLy8gRVJST1I6IGNvbnN0cnVjdG9yIHByaXZhdGUKICAgICAgICAvLyBsb2NrID0gTG9ja0d1YXJkKG10eCk7Ly8gRVJST1I6IG5vIGRlZmF1bHQgYXNzaWdubWVudCBvcGVyYXRvcgogICAgfQogICAgCn0K