Scoped Locking is a pattern? I can't answer well until I read the associated portion of POSA2. I used this way to acquire and release a lock so normally.
The Scoped Locking C++ idiom ensures that a lock is acquired when control enters a scope and released automatically when control leaves the scope, regardless of the return path from the scope.
Define a guard class whose constructor automatically acquires a lock when control enters a scope and whose destructor automatically releases the lock when control leaves the scope. Instantiate instances of the guard class to acquire/release locks in method or block scopes that define critical sections.
本文介绍了 Scoped Locking 模式,这是一种确保锁在进入作用域时被获取,并在离开作用域时自动释放的设计模式。通过定义一个守护类,其构造函数在进入作用域时自动获取锁,析构函数则在退出作用域时释放锁。
756

被折叠的 条评论
为什么被折叠?



