[reSIProcate] static StatisticsMessage::AtomicPayload appStats; in poll() may not thread safe

maodonghu hhmmdd at tom.com
Tue Oct 17 21:18:54 CDT 2006


hi, 

I found my multi-thread program that using resiprocate will crashed sometimes when startup, the place is 

void
StatisticsMessage::AtomicPayload::loadIn(const Payload& payload)
{
   Lock lock(mMutex); // --> here cause crash, because the mMutex may have not finished its constructor yet.
   Payload::operator=(payload);
}

then I research the source code, I found

void 
StatisticsManager::poll()
{
   // get snapshot data now..
   tuFifoSize = mStack.mTransactionController.getTuFifoSize();
   transportFifoSizeSum = mStack.mTransactionController.sumTransportFifoSizes();
   transactionFifoSize = mStack.mTransactionController.getTransactionFifoSize();
   activeTimers = mStack.mTransactionController.getTimerQueueSize();
   activeClientTransactions = mStack.mTransactionController.getNumClientTransactions();
   activeServerTransactions = mStack.mTransactionController.getNumServerTransactions();   

   static StatisticsMessage::AtomicPayload appStats; // --> here may not thread safe
   appStats.loadIn(*this);

   // let the app do what it wants with it
   mStack.post(StatisticsMessage(appStats));
}
 		

Because I have multi-SipStacks in my program, so I have multi-StackThread, I think the usage of static local variable here may not thread safe, appStats should be a static member of class StatisticsManager.

the MSDN help also tell us:

Note  
Assigning to a static local variable is not thread safe and is not recommended as a programming practice.
 


        maodonghu
        hhmmdd at tom.com
          2006-10-18




More information about the resiprocate-devel mailing list