|
一直想单独测试一下ACE_Recursive_Thread_Mutex在不同操作系统下的稳定性。
于是趁早上刚到公司的闲暇时间,写了一个小测试用例。- // ACE_MetuxTest.cpp : 定义控制台应用程序的入口点。
- //
- #include "ace/Malloc.h"
- #include "ace/Malloc_T.h"
- #include "ace/Thread_Mutex.h"
- #include "ace/Singleton.h"
- #include "ace/OS_NS_Thread.h"
- #include "ace/Time_Value.h"
- #include "ace/Null_Mutex.h"
- #include "ace/OS_NS_unistd.h"
- class CTestMutex
- {
- public:
- CTestMutex()
- {
- m_nCount = 0;
- }
- void Add()
- {
- ACE_Guard<ACE_Recursive_Thread_Mutex> WGuard(m_ThreadWriteLock);
- m_nCount++;
- };
- void Display()
- {
- printf("[CTestMutex::Display]nCount=%d.\n", m_nCount);
- }
- private:
- ACE_Recursive_Thread_Mutex m_ThreadWriteLock;
- unsigned int m_nCount;
- };
- typedef ACE_Singleton<CTestMutex, ACE_Null_Mutex> App_TestMutex;
- //线程执行
- void* ThreadProc(void* argv)
- {
- for(int i = 0; i < 1000; i++)
- {
- App_TestMutex::instance()->Add();
- }
- return 0;
- }
- int main(int argc, char* argv[])
- {
- for(int i = 0; i < 10; i++)
- {
- //DWORD ThreadID = 0;
- //CreateThread(NULL, NULL, ThreadProc, (LPVOID)NULL, NULL, &ThreadID);
- ACE_thread_t threadId;
- ACE_hthread_t threadHandle;
- ACE_Thread::spawn((ACE_THR_FUNC)ThreadProc, //线程执行函数
- NULL,
- THR_JOINABLE | THR_NEW_LWP,
- &threadId,
- &threadHandle);
- }
- ACE_Time_Value tvSleep(2, 0);
- ACE_OS::sleep(tvSleep);
- App_TestMutex::instance()->Display();
- getchar();
- return 0;
- }
复制代码 在linux下和windows下测试,都没问题。
在这里记录一下。
|
|