non-reentrant mutex problem in objectRef.cc

Mark Little M.C.Little@ncl.ac.uk
Mon, 10 Nov 1997 10:20:06 +0000


> I have an implementation object A which contains a reference to some
> other Orb object B. For simplicity assume there's only a single thread
> running in the application when I call _dispose on A, and in A's
> destructor it
> calls release on B. The problem is that omniOrb (correctly) protects
> its internal object tables with a mutex, and A effectively acquires this
> when _dispose is called. _dispose then (while still holding the mutex)
> calls the destructor of A. When A calls release on B it dives back
> into objectRef to get the mutex and because pthread mutexes on Solaris
> aren't reentrant, the thread blocks waiting for itself.

Here's the modified disposeObject from objectRef.cc which fixes
the above problem:


void
omni::disposeObject(omniObject *obj)
{
  if (obj->is_proxy())
    return;
  omniObject::objectTableLock.lock();
  if (obj->getRefCount() <= 0) {
    omniObject::objectTableLock.unlock();
    throw CORBA::INV_OBJREF(0,CORBA::COMPLETED_NO);
  }
  else
    obj->setRefCount(obj->getRefCount()-1);

  if (obj->getRefCount() == 0) {
  omniObject::objectTableLock.unlock();      
    // object has already been removed from the object table
    delete obj;
  }
  else {
    obj->pd_disposed = 1;
  omniObject::objectTableLock.unlock();    
  }

  return;
}


All the best,

Mark.

-----------------------------------------------------------------------
SENDER : Dr. Mark Little, Arjuna Project, Distributed Systems Research.
PHONE  : +44 191 222 8066, FAX : +44 191 222 8232
POST   : Department of Computing Science, University of Newcastle upon
	 Tyne, UK, NE1 7RU
EMAIL  : M.C.Little@newcastle.ac.uk