1 #include "ace/OS_NS_unistd.h"
3 #include "ace/Monitor_Control/Monitor_Control.h"
5 #include "examples/Monitor/MC_Test_Utilities.h"
7 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
9 class Worker
: public ACE_Task_Base
19 /// Subclass of ACE_Task_Base, meaning that the override of
20 /// the svc() method below will run in a new thread when
21 /// activate() is called on a class instance.
22 class Monitor_Checker
: public ACE_Task_Base
27 /// Get an instance of the MC service singleton.
28 MC_ADMINMANAGER
* mgr
=
29 ACE_Dynamic_Service
<MC_ADMINMANAGER
>::instance ("MC_ADMINMANAGER");
31 /// Call on the administrator class to look up the desired monitors.
32 ACE::Monitor_Control::Monitor_Base
*thread_monitor
=
33 mgr
->admin ().monitor_point ("OS/System/NumThreads");
35 if (thread_monitor
!= 0)
37 /// Query each monitor for its data every 2 seconds, and call the
38 /// appropriate display function.
39 for (int i
= 0; i
< 5; ++i
)
43 Monitor_Control_Types::Data
data (thread_monitor
->type ());
44 thread_monitor
->retrieve (data
);
45 MC_Test_Utilities::display_num_threads (data
);
48 thread_monitor
->remove_ref ();
55 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */
58 ACE_TMAIN (int /* argc */, ACE_TCHAR
* /* argv */ [])
60 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
62 /// Set the timer for # of threads check at 2 sec.
63 Monitor_Base
*num_threads_monitor
=
64 create_os_monitor
<NUM_THREADS_MONITOR
> (0, ACE_Time_Value (2));
66 /// Runs the reactor's event loop in a separate thread so the timer(s)
67 /// can run concurrently with the application.
68 START_PERIODIC_MONITORS
;
70 /// Run the monitor checker in a separate thread.
71 Monitor_Checker monitor_checker
;
72 monitor_checker
.activate ();
74 /// Spawn 100 threads, sleep until they finish.
76 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
, 100);
80 /// End the reactor's event loop, stopping the timer(s).
81 STOP_PERIODIC_MONITORS
;
83 num_threads_monitor
->remove_ref ();
85 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */