Re: [reSIProcate] static StatisticsMessage::AtomicPayload appStats; in poll() may not thread safe
hi maodonghu,
you must compile with /MD or /MT option in you all project.
jinti
在06-10-18,maodonghu <
hhmmdd@xxxxxxx> 写道: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@xxxxxxx
2006-10-18
_______________________________________________
resiprocate-devel mailing list
resiprocate-devel@xxxxxxxxxxxxxxxxxxx
https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel