|
楼主 |
发表于 2010-1-12 16:31:37
|
显示全部楼层
但是这段代码
- #include "ace/Timer_Queue.h"
- #include "ace/Reactor.h"
- #include "ace/High_Res_Timer.h"
- #include "ace/Trace.h"
- #include "ace/Recursive_Thread_Mutex.h"
- #include "ace/Log_Msg.h"
- #include "ace/Thread_Manager.h"
- #include "ace/OS.h"
- void* f (void* mutex) {
- ACE_Guard<ACE_Recursive_Thread_Mutex> lock( *(ACE_Recursive_Thread_Mutex*)mutex );
- ACE_DEBUG ((LM_DEBUG, "haha f\n"));
- ACE_OS::sleep(2);
- return 0;
- }
- int ACE_TMAIN(int argc, ACE_TCHAR **argv)
- {
- ACE_Recursive_Thread_Mutex mutex;
- ACE_Guard<ACE_Recursive_Thread_Mutex> lock( mutex );
- lock.release();
- lock.release();
- ACE_DEBUG ((LM_DEBUG, "haha 1\n"));
- ACE_Thread_Manager::instance()->spawn((ACE_THR_FUNC)f, (void*) &mutex, THR_DETACHED | THR_SCOPE_PROCESS);
- ACE_OS::sleep(1);
- ACE_DEBUG ((LM_DEBUG, "haha 2\n"));
- lock.release();
- ACE_Guard<ACE_Recursive_Thread_Mutex> lock1( mutex );
- ACE_DEBUG ((LM_DEBUG, "haha 3\n"));
- lock.release();
- ACE_DEBUG ((LM_DEBUG, "haha here?\n"));
- ACE_Thread_Manager::instance()->wait();
- ACE_DEBUG ((LM_DEBUG, "haha there?\n"));
-
- return 0;
- }
复制代码
崩溃的几率很高。但我把ACE_DEBUG语句注释掉或者改成cout<< 就没崩溃过。
有时候崩溃又很难重现,郁闷。。。
一直对ACE_DEBUG的线程安全性存疑。。。 |
|