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

Jason Fischl jason at counterpath.com
Wed Oct 18 12:19:29 CDT 2006


This looks like a bug to me. We should use a stack variable instead of
a static.

Jason


On 10/17/06, maodonghu <hhmmdd at tom.com> wrote:
> 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



More information about the resiprocate-devel mailing list