Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / RTScheduling / Thread_Cancel / test.cpp
blob8877b1c7f3b1bc16aa4b33b80d70ca04f70e3fb9
1 #include "Thread_Task.h"
2 #include "ace/OS_NS_unistd.h"
3 #include "../Scheduler.h"
4 #include "tao/RTScheduling/RTScheduler_Manager.h"
5 #include "tao/ORB_Core.h"
7 int
8 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
10 try
12 CORBA::ORB_var orb =
13 CORBA::ORB_init (argc,
14 argv);
16 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
18 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
20 TAO_Scheduler scheduler (orb.in ());
22 manager->rtscheduler (&scheduler);
24 Thread_Task task;
26 task.activate_task (orb.in ());
28 ACE_DEBUG ((LM_DEBUG,
29 "Waiting for Threads to Activate...\n"));
30 ACE_OS::sleep (5);
31 ACE_DEBUG ((LM_DEBUG,
32 "Threads Activated\n"));
34 ACE_DEBUG ((LM_DEBUG,
35 "Cancelling Threads.....\n"));
37 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
39 RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());
41 for (int i = 0; i < 4; i++)
43 RTScheduling::DistributableThread_var DT = current->lookup ((task.guids ())[i]);
45 DT->cancel ();
48 orb->run ();
50 ACE_Thread_Manager::instance ()->wait ();
52 orb->destroy ();
54 catch (const CORBA::Exception& ex)
56 ex._tao_print_exception ("Caught exception:");
57 return 1;
60 return 0;