在ACE 6.0.0 里提供了一个Reactor示例程序,对其分析一下(在代码的注释里)。
Reactors_Test.cpp文件(在 \ACE-6.0.0\ACE_wrappers\tests\ 目录下):
// $Id: Reactors_Test.cpp 91671 2010-09-08 18:39:23Z johnnyw $
// ============================================================================
//
// = LIBRARY
// tests
//
// = FILENAME
// Reactors_Test.cpp
//
// = DESCRIPTION
// This is a test that performs a torture test of multiple
// <ACE_Reactors> and <ACE_Tasks> in the same process.
//
// = AUTHOR
// Prashant Jain <pjain@cs.wustl.edu>,
// Detlef Becker <Detlef.Becker@med.siemens.de>, and
// Douglas C. Schmidt <schmidt@cs.wustl.edu>
//
// ============================================================================
#include "test_config.h"
#include "ace/Task.h"
#include "ace/Reactor.h"
#include "ace/Atomic_Op.h"
#include "ace/Recursive_Thread_Mutex.h"
#if defined (ACE_HAS_THREADS)
ACE_Thread_Manager *thr_mgr;
static const int MAX_TASKS = 20;
class Test_Task : public ACE_Task<ACE_MT_SYNCH&g