本文整理汇总了C++中typenamem::scoped_lock::try_acquire方法的典型用法代码示例。如果您正苦于以下问题:C++ scoped_lock::try_acquire方法的具体用法?C++ scoped_lock::try_acquire怎么用?C++ scoped_lock::try_acquire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenamem::scoped_lock
的用法示例。
在下文中一共展示了scoped_lock::try_acquire方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestTryAcquire_OneThread
void TestTryAcquire_OneThread( const char * mutex_name ) {
M tested_mutex;
typename M::scoped_lock lock1;
if( lock1.try_acquire(tested_mutex) )
lock1.release();
else
REPORT("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
{
if( M::is_recursive_mutex ) {
typename M::scoped_lock lock2(tested_mutex);
if( lock1.try_acquire(tested_mutex) )
lock1.release();
else
REPORT("ERROR for %s: try_acquire on recursive lock failed though it should not\n", mutex_name);
//windows.. -- both are recursive
} else {
typename M::scoped_lock lock2(tested_mutex);
if( lock1.try_acquire(tested_mutex) )
REPORT("ERROR for %s: try_acquire succeeded though it should not\n", mutex_name);
}
}
if( lock1.try_acquire(tested_mutex) )
lock1.release();
else
REPORT("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
}
示例2: TestTryAcquire_OneThread
void TestTryAcquire_OneThread( const char * mutex_name ) {
M tested_mutex;
typename M::scoped_lock lock1;
if( lock1.try_acquire(tested_mutex) )
lock1.release();
else
STD::printf("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
{
typename M::scoped_lock lock2(tested_mutex);
if( lock1.try_acquire(tested_mutex) )
STD::printf("ERROR for %s: try_acquire succeeded though it should not\n", mutex_name);
}
if( lock1.try_acquire(tested_mutex) )
lock1.release();
else
STD::printf("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
}
示例3: TestTryAcquireReader_OneThread
void TestTryAcquireReader_OneThread( const char * mutex_name ) {
M tested_mutex;
typename M::scoped_lock lock1;
if( M::is_rw_mutex ) {
if( lock1.try_acquire(tested_mutex, false) )
lock1.release();
else
REPORT("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
{
typename M::scoped_lock lock2(tested_mutex, false);
if( lock1.try_acquire(tested_mutex) )
REPORT("ERROR for %s: try_acquire succeeded though it should not\n", mutex_name);
lock2.release();
lock2.acquire(tested_mutex, true);
if( lock1.try_acquire(tested_mutex, false) )
REPORT("ERROR for %s: try_acquire succeeded though it should not\n", mutex_name);
}
if( lock1.try_acquire(tested_mutex, false) )
lock1.release();
else
REPORT("ERROR for %s: try_acquire failed though it should not\n", mutex_name);
}
}