I am trying to use nsAutoMonitor to protect some code from reentrancy, 
however I am being thwarted by some wierd problems that result in 
illegal memory accesses. (Platform: Windows 2K, MSVC 6.0, Mozilla 0.8 
code base)

The code is basically as follows:

nsresult
CPackage::Init( nsIFile* pPackageFile )
{
   nsresult rv = NS_OK;

   /* Create a monitor for controlling access to the file */
   m_pmonPackage = PR_NewMonitor();
   if( !m_pmonPackage ) return NS_ERROR_OUT_OF_MEMORY;

   nsAutoMonitor monitor(m_pmonPackage);

   /* Processing */

}

The monitor is created, OK the nsAutoMonitor appears to instantiate OK, 
but once the processing has finished the destructor of  nsAutoMonitor 
fails, because the mMonitor member variable of nsAutoMonitor has 
miraculously become set to 1. N.B. m_pmonPackage is a member of  the 
CPackage class.

Any theories/suggestions would be appreciated


Reply via email to