当前位置: 首页>>代码示例>>C++>>正文


C++ CCriticalSection::enter方法代码示例

本文整理汇总了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
	}
}
开发者ID:Aharobot,项目名称:mrpt,代码行数:16,代码来源:CCriticalSection_unittest.cpp

示例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;
	}
}
开发者ID:GYengera,项目名称:mrpt,代码行数:35,代码来源:test.cpp

示例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);
}
开发者ID:Aharobot,项目名称:mrpt,代码行数:17,代码来源:CCriticalSection_unittest.cpp

示例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();
}
开发者ID:Aharobot,项目名称:mrpt,代码行数:8,代码来源:CCriticalSection_unittest.cpp


注:本文中的CCriticalSection::enter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。