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 #if defined (ACE_OPENVMS)
22 // less threads on OpenVMS otherwise this test
23 // (although working correctly) takes far too long.
24 const size_t N_THREADS
= 10;
26 const size_t N_THREADS
= 20;
28 const size_t N_ITERATIONS
= 100;
31 class A_i
: public virtual POA_A
35 class B_i
: public virtual POA_C
38 B_i (PortableServer::POA_ptr poa
)
39 : poa_ (PortableServer::POA::_duplicate (poa
))
45 PortableServer::ServantBase_var servant
= new A_i
;
46 PortableServer::ObjectId_var tmp
= this->poa_
->activate_object (servant
.in());
47 CORBA::Object_var obj
= this->poa_
->servant_to_reference (servant
.in());
48 return A::_narrow (obj
.in ());
52 PortableServer::POA_var poa_
;
55 // Thread for ORB->run()
56 ACE_THR_FUNC_RETURN
OrbRunThread (void*);
58 // Thread to run the test
59 ACE_THR_FUNC_RETURN
TestThread (void*);
62 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
67 CORBA::ORB_var Orb
= CORBA::ORB_init (argc
, argv
);
69 CORBA::Object_var pPoaObj
=
70 Orb
->resolve_initial_references ("RootPOA");
71 PortableServer::POA_var Poa
= PortableServer::POA::_narrow (pPoaObj
.in ());
72 PortableServer::POAManager_var pMgr
= Poa
->the_POAManager ();
75 CORBA::Object_var pNSObj
=
76 Orb
->resolve_initial_references ("SimpleNamingService");
77 SimpleNamingService_var NameService
=
78 SimpleNamingService::_narrow (pNSObj
.in ());
80 if (CORBA::is_nil (NameService
.in ()))
83 "ERROR: Could not locate the Simple Naming Service\n"));
87 ACE_Thread_Manager orb_thread
;
88 orb_thread
.spawn (OrbRunThread
, Orb
.in (), THR_NEW_LWP
| THR_DETACHED
);
91 PortableServer::ServantBase_var servant
= new B_i (Poa
.in ());
92 PortableServer::ObjectId_var tmp
= Poa
->activate_object (servant
.in());
93 CORBA::Object_var b
= Poa
->servant_to_reference (servant
.in());
95 NameService
->bind (b
.in ());
98 ACE_Thread_Manager threads
;
99 threads
.spawn_n (N_THREADS
, TestThread
, NameService
.in ());
100 ACE_DEBUG ((LM_INFO
, "All threads spawned.\n"));
107 } //destructor of ACE_Thread_Manager = implicit join
108 catch (const CORBA::Exception
& ex
)
110 ACE_DEBUG ((LM_ERROR
, "Corba Exception: %s\n", ex
._info ().c_str ()));
118 OrbRunThread (void *arg
)
121 CORBA::ORB::_duplicate (reinterpret_cast<CORBA::ORB_ptr
> (arg
));
127 catch (const CORBA::Exception
& ex
)
129 ACE_DEBUG ((LM_ERROR
,
130 "In OrbRunThread: Corba Exception: %s\n",
131 ex
._info ().c_str ()));
137 TestThread (void *arg
)
139 SimpleNamingService_var NameService
=
140 SimpleNamingService::_duplicate (reinterpret_cast<SimpleNamingService_ptr
> (arg
));
144 for (size_t i (0); i
< N_ITERATIONS
; ++i
)
146 CORBA::Object_var obj
= NameService
->resolve ();
147 C_var b
= C::_narrow (obj
.in ());
148 A_var tmp
= b
->makeA ();
150 ACE_DEBUG ((LM_INFO
, "(%t) collocated call returned\n"));
153 catch (const CORBA::Exception
& ex
)
155 ACE_DEBUG ((LM_ERROR
,
156 "In TestThread: Corba Exception: %s\n",
157 ex
._info ().c_str ()));