Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / ThreadManagement / ExitHandler.cpp
blob4d62f6dc2be8885b48139c07097799dc5e7725d1
1 // Listing 1 code/ch13
2 #include "ace/Task.h"
3 #include "ace/Log_Msg.h"
5 class ExitHandler : public ACE_At_Thread_Exit
7 public:
8 virtual void apply ()
10 ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) is exiting\n")));
12 // Shut down all devices.
15 // Listing 1
16 // Listing 2 code/ch13
17 class HA_CommandHandler : public ACE_Task_Base
19 public:
20 HA_CommandHandler(ExitHandler& eh) : eh_(eh)
21 { }
23 virtual int svc ()
25 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) starting up\n")));
27 this->thr_mgr ()->at_exit (eh_);
29 // Do something.
31 // Forcefully exit.
32 ACE_Thread::exit ();
34 // NOT REACHED
35 return 0;
38 private:
39 ExitHandler& eh_;
41 // Listing 2
42 // Listing 3 code/ch13
43 int ACE_TMAIN (int, ACE_TCHAR *[])
45 ExitHandler eh;
47 HA_CommandHandler handler (eh);
48 handler.activate ();
50 ACE_Thread_Manager::instance ()->wait ();
51 return 0;
53 // Listing 3
54 #if 0
55 // Listing 4 code/ch13
56 int ACE_TMAIN (int, ACE_TCHAR *[])
58 ExitHandler eh;
59 ACE_Thread_Manager tm;
61 HA_CommandHandler handler (eh);
62 handler.thr_mgr (&tm);
63 handler.activate ();
65 tm.wait();
66 return 0;
68 // Listing 4
69 #endif