ACE_Manual_Event
类
唤醒所有正在等待的线程,并重新设置信号
常用构造:
ACE_Manual_Event ( 1 ) 表当前对象已经准备就绪,一旦有线程处于等待状态,就将触发并重置事件
异常处理的语法结构:
ACE_SEH_TRY
{
//可能发生异常的代码
}
ACE_SEH_EXCEPT ( EXCEPTION_EXECUTE_HANDLER )
{
//发生异常后的处理
}
例子(来源于 ACE 自带的例子)如下
#include "ace/WFMO_Reactor.h"
ACE_RCSID ( WFMO_Reactor , Exceptions , "Exceptions.cpp,v 4.1 2002/04/25 04:40:42 irfan Exp" )
class Event_Handler : public ACE_Event_Handler
{
public :
Event_Handler ( void )
: event_ ( 1 )
{
ACE_DEBUG (( LM_DEBUG ,
"Event_Handler created/n" ));
}
~ Event_Handler ( void )
{
ACE_DEBUG (( LM_DEBUG ,
"Event_Handler destroyed/n" ));
}
int handle_signal ( int signum , siginfo_t * = 0 , ucontext_t * = 0 )
{
char * cause_exception = 0 ;
char a = * cause_exception ;
return 0 ;
}
ACE_HANDLE get_handle ( void ) const
{
return this -> event_ . handle ();
}
private :
ACE_Manual_Event event_ ;
};
class ACE_WFMO_Reactor_Test
{
public :
static void doit ( ACE_WFMO_Reactor & wfmo_reactor )
{
for ( int i = 1 ; i < = 10 ; i ++)
{
ACE_DEBUG (( LM_DEBUG ,
"Active threads in WFMO_Reactor (before handle_events) = %d/n" ,
wfmo_reactor . active_threads_ ));
ACE_SEH_TRY
{
wfmo_reactor . handle_events ();
}
ACE_SEH_EXCEPT ( EXCEPTION_EXECUTE_HANDLER )
{
ACE_DEBUG (( LM_DEBUG ,
"Exception occurred/n" ));
}
ACE_DEBUG (( LM_DEBUG ,
"Active threads in WFMO_Reactor (after handle_events) = %d/n" ,
wfmo_reactor . active_threads_ ));
}
}
};
int
ACE_TMAIN ( int , ACE_TCHAR *[])
{
Event_Handler handler ;
ACE_WFMO_Reactor wfmo_reactor ;
wfmo_reactor . register_handler (& handler );
ACE_WFMO_Reactor_Test :: doit ( wfmo_reactor );
return 0 ;
}
唤醒所有正在等待的线程,并重新设置信号
常用构造:
ACE_Manual_Event ( 1 ) 表当前对象已经准备就绪,一旦有线程处于等待状态,就将触发并重置事件
异常处理的语法结构:
ACE_SEH_TRY
{
//可能发生异常的代码
}
ACE_SEH_EXCEPT ( EXCEPTION_EXECUTE_HANDLER )
{
//发生异常后的处理
}
例子(来源于 ACE 自带的例子)如下
#include "ace/WFMO_Reactor.h"
ACE_RCSID ( WFMO_Reactor , Exceptions , "Exceptions.cpp,v 4.1 2002/04/25 04:40:42 irfan Exp" )
class Event_Handler : public ACE_Event_Handler
{
public :
Event_Handler ( void )
: event_ ( 1 )
{
ACE_DEBUG (( LM_DEBUG ,
"Event_Handler created/n" ));
}
~ Event_Handler ( void )
{
ACE_DEBUG (( LM_DEBUG ,
"Event_Handler destroyed/n" ));
}
int handle_signal ( int signum , siginfo_t * = 0 , ucontext_t * = 0 )
{
char * cause_exception = 0 ;
char a = * cause_exception ;
return 0 ;
}
ACE_HANDLE get_handle ( void ) const
{
return this -> event_ . handle ();
}
private :
ACE_Manual_Event event_ ;
};
class ACE_WFMO_Reactor_Test
{
public :
static void doit ( ACE_WFMO_Reactor & wfmo_reactor )
{
for ( int i = 1 ; i < = 10 ; i ++)
{
ACE_DEBUG (( LM_DEBUG ,
"Active threads in WFMO_Reactor (before handle_events) = %d/n" ,
wfmo_reactor . active_threads_ ));
ACE_SEH_TRY
{
wfmo_reactor . handle_events ();
}
ACE_SEH_EXCEPT ( EXCEPTION_EXECUTE_HANDLER )
{
ACE_DEBUG (( LM_DEBUG ,
"Exception occurred/n" ));
}
ACE_DEBUG (( LM_DEBUG ,
"Active threads in WFMO_Reactor (after handle_events) = %d/n" ,
wfmo_reactor . active_threads_ ));
}
}
};
int
ACE_TMAIN ( int , ACE_TCHAR *[])
{
Event_Handler handler ;
ACE_WFMO_Reactor wfmo_reactor ;
wfmo_reactor . register_handler (& handler );
ACE_WFMO_Reactor_Test :: doit ( wfmo_reactor );
return 0 ;
}