本文整理汇总了C++中CCriticalSection::enter方法的典型用法代码示例。如果您正苦于以下问题:C++ CCriticalSection::enter方法的具体用法?C++ CCriticalSection::enter怎么用?C++ CCriticalSection::enter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCriticalSection
的用法示例。
在下文中一共展示了CCriticalSection::enter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: my_CriticalSections_NoDoubleEnter
// TEST 2: Assure that a double-enter in a CS will raise an exception
// ----------------------------------------------------------------------------
void my_CriticalSections_NoDoubleEnter()
{
CCriticalSection cs;
cs.enter();
try{
cs.enter(); // Must fail!
// Shouldn't reach here.
EXPECT_TRUE(false) << "Fail to detect a double 'enter()' into a critical section!\n";
}
catch(std::exception&)
{
// OK
}
}
示例2: main
// ------------------------------------------------------
// MAIN
// ------------------------------------------------------
int main()
{
try
{
csTest.m_debugOut = &myOutStream;
cout << "Part 1: Normal usage, we'll lock, then unlock the critical section" << endl << endl;
{
synch::CCriticalSectionLocker locker(&csTest);
cout << "I possess the crit. section..." << endl;
}
cout << endl << "Part 2: Bad usage, we'll lock, then lock again the critical section" << endl << endl;
{
synch::CCriticalSectionLocker locker(&csTest);
csTest.enter();
cout << "This message shouldn't appear, an exception raised before instead!!" << endl;
}
return 0;
} catch (std::exception &e)
{
std::cout << "MRPT exception caught: " << e.what() << std::endl;
return -1;
}
catch (...)
{
printf("Untyped exception!!");
return -1;
}
}
示例3: my_CriticalSections_Multi
void my_CriticalSections_Multi()
{
randomGenerator.randomize();
for (int i=1;i<=10;i++)
createThread( thread_example, i );
// Wait all threads exit:
int cnt;
do
{
sleep(10);
csCounter.enter();
cnt = counter;
csCounter.leave();
} while (cnt);
}
示例4: my_CriticalSections_Simple
// TEST 1: Just test if creating a CS doesn't launch an exception or lock.
// ----------------------------------------------------------------------------
void my_CriticalSections_Simple()
{
CCriticalSection cs;
cs.enter();
cs.leave();
}