2 * CollocationLockup.cpp
3 * This is regression test against bug #2130.
4 * It tests a deadlock between a thread making a collocated invocation
5 * (which holds a lock on the ORB core and attempts to lock the POA) and a
6 * thread activating a servant (which locks the POA and attempts to lock the
9 * This test was developed from a test submitted by Rick Marlborough for bug
10 * #2297 and refined by Paul Calabrese.
14 #include "SimpleNamingServiceC.h"
16 #include "ace/Thread_Manager.h"
17 #include "ace/SString.h"
21 const size_t N_THREADS
= 20;
22 const size_t N_ITERATIONS
= 100;
25 class A_i
: public virtual POA_A
29 class B_i
: public virtual POA_C
32 B_i (PortableServer::POA_ptr poa
)
33 : poa_ (PortableServer::POA::_duplicate (poa
))
39 PortableServer::ServantBase_var servant
= new A_i
;
40 PortableServer::ObjectId_var tmp
= this->poa_
->activate_object (servant
.in());
41 CORBA::Object_var obj
= this->poa_
->servant_to_reference (servant
.in());
42 return A::_narrow (obj
.in ());
46 PortableServer::POA_var poa_
;
49 // Thread for ORB->run()
50 ACE_THR_FUNC_RETURN
OrbRunThread (void*);
52 // Thread to run the test
53 ACE_THR_FUNC_RETURN
TestThread (void*);
56 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
61 CORBA::ORB_var Orb
= CORBA::ORB_init (argc
, argv
);
63 CORBA::Object_var pPoaObj
=
64 Orb
->resolve_initial_references ("RootPOA");
65 PortableServer::POA_var Poa
= PortableServer::POA::_narrow (pPoaObj
.in ());
66 PortableServer::POAManager_var pMgr
= Poa
->the_POAManager ();
69 CORBA::Object_var pNSObj
=
70 Orb
->resolve_initial_references ("SimpleNamingService");
71 SimpleNamingService_var NameService
=
72 SimpleNamingService::_narrow (pNSObj
.in ());
74 if (CORBA::is_nil (NameService
.in ()))
77 "ERROR: Could not locate the Simple Naming Service\n"));
81 ACE_Thread_Manager orb_thread
;
82 orb_thread
.spawn (OrbRunThread
, Orb
.in (), THR_NEW_LWP
| THR_DETACHED
);
85 PortableServer::ServantBase_var servant
= new B_i (Poa
.in ());
86 PortableServer::ObjectId_var tmp
= Poa
->activate_object (servant
.in());
87 CORBA::Object_var b
= Poa
->servant_to_reference (servant
.in());
89 NameService
->bind (b
.in ());
92 ACE_Thread_Manager threads
;
93 threads
.spawn_n (N_THREADS
, TestThread
, NameService
.in ());
94 ACE_DEBUG ((LM_INFO
, "All threads spawned.\n"));
101 } //destructor of ACE_Thread_Manager = implicit join
102 catch (const CORBA::Exception
& ex
)
104 ACE_DEBUG ((LM_ERROR
, "Corba Exception: %s\n", ex
._info ().c_str ()));
112 OrbRunThread (void *arg
)
115 CORBA::ORB::_duplicate (reinterpret_cast<CORBA::ORB_ptr
> (arg
));
121 catch (const CORBA::Exception
& ex
)
123 ACE_DEBUG ((LM_ERROR
,
124 "In OrbRunThread: Corba Exception: %s\n",
125 ex
._info ().c_str ()));
131 TestThread (void *arg
)
133 SimpleNamingService_var NameService
=
134 SimpleNamingService::_duplicate (reinterpret_cast<SimpleNamingService_ptr
> (arg
));
138 for (size_t i (0); i
< N_ITERATIONS
; ++i
)
140 CORBA::Object_var obj
= NameService
->resolve ();
141 C_var b
= C::_narrow (obj
.in ());
142 A_var tmp
= b
->makeA ();
144 ACE_DEBUG ((LM_INFO
, "(%t) collocated call returned\n"));
147 catch (const CORBA::Exception
& ex
)
149 ACE_DEBUG ((LM_ERROR
,
150 "In TestThread: Corba Exception: %s\n",
151 ex
._info ().c_str ()));