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

maodonghu hhmmdd at tom.com
Tue Oct 17 22:00:01 CDT 2006


Hi, shen jinti 

  By the way, I use Pentinum D, it has 2 CPU, so the exception may be easy to encounter.

======== 2006-10-18 10:37:34  ========

hi maodonghu,

    you must compile with  /MD or /MT option in you all project.
    
    jinti



在06-10-18,maodonghu < hhmmdd at tom.com> 写道:
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

_______________________________________________
resiprocate-devel mailing list
resiprocate-devel at list.sipfoundry.org
https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel



= = = = = = = = = = = = = = = = = = = = = = 

              maodonghu
              hhmmdd at tom.com
               2006-10-18
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20061018/8d695b1c/attachment.htm>


More information about the resiprocate-devel mailing list