Index: src/lib/omniORB/orbcore/poa.cc
===================================================================
RCS file: /cvsroot/omniorb/omni/src/lib/omniORB/orbcore/Attic/poa.cc,v
retrieving revision 1.2.2.43
diff -u -r1.2.2.43 poa.cc
--- src/lib/omniORB/orbcore/poa.cc	8 Apr 2005 00:06:13 -0000	1.2.2.43
+++ src/lib/omniORB/orbcore/poa.cc	16 May 2005 16:35:46 -0000
@@ -2116,18 +2116,33 @@
   ASSERT_OMNI_TRACEDMUTEX_HELD(poa_lock, 0);
   OMNIORB_ASSERT(pd_dying);
 
-  while( pd_children.length() ) {
-    try {
-      pd_children[0]->destroy(etherealize_objects, 1);
+  PortableServer::POA_var child;
+  while (1) {
+    {
+      omni_tracedmutex_lock sync(poa_lock);
+      if (pd_children.length())
+	child = PortableServer::POA::_duplicate(pd_children[0]);
+      else
+	child = PortableServer::POA::_nil();
     }
-    catch(CORBA::OBJECT_NOT_EXIST& ex) {
-      // Race with another thread destroying a child POA.
-      omni_thread::sleep(0, 100000000);
+    if (!CORBA::is_nil(child)) {
+      try {
+	child->destroy(etherealize_objects, 1);
+      }
+      catch(CORBA::OBJECT_NOT_EXIST& ex) {
+	// Race with another thread destroying a child POA.
+	omni_thread::sleep(0, 100000000);
+      }
+      catch (...) {
+	omniORB::logs(2, "Unexpected exception in do_destroy.");
+      }
     }
-    catch (...) {
-      omniORB::logs(2, "Unexpected exception in do_destroy.");
+    else {
+      // No more children
+      break;
     }
   }
+  child = PortableServer::POA::_nil();
 
   OMNIORB_ASSERT(pd_children.length() == 0);
 
