[reSIProcate] [reSIProcate-commit] resiprocate 8871 sgodin: -fixed potential multi-threading issues with static member variable initialization

Kennard White kennard_white at logitech.com
Wed Dec 1 13:01:47 CST 2010


Wow. Did quick test under gcc4&linux, and same behavior. I didn't realize
there was a run-time cost (plus thread risk) to static function variable
initializers.

Thanks,
Kennard

On Wed, Dec 1, 2010 at 10:18 AM, Scott Godin <sgodin at sipspectrum.com> wrote:

> Hi Kennard,
>
> Static member variables are constructed the first time the function is
> called.  If multiple threads call a particular member function (that
> contains a static variable) for the first time at the exact same time (ie.
> thread preempts in the middle of object construction), then both threads can
> end up trying to construct the same static object.  I was seeing this
> behaviour under Visual Studio 2008, it possible that this problem does not
> exist on other compilers.  Moving the static variables outside of the member
> function causes them to be created when the application is initialized, thus
> avoiding this race.
>
> Scott
>
> On Wed, Dec 1, 2010 at 1:00 PM, Kennard White <kennard_white at logitech.com>wrote:
>
>> Hi Scott,
>>
>> There is some intricacy of C++ that I don't understand. Could you explain
>> the thread safety issue below? Is there a difference in when the
>> constructors/destructors are called?
>>
>> Thanks,
>> Kennard
>>
>> +static const Data errorContextData("Contents");
>>  const Data&
>>  Contents::errorContext() const
>>  {
>> -   static const Data context("Contents");
>> -   return context;
>> +   return errorContextData;
>>  }
>>
>>
>> On Sat, Nov 27, 2010 at 7:37 AM, <svn at resiprocate.org> wrote:
>>
>>>  Projectresiprocate New Revision8871<http://svn.resiprocate.org/viewsvn/resiprocate?view=rev&rev=8871>
>>> Committersgodin (Scott Godin) Date2010-11-27 09:37:49 -0600 (Sat, 27 Nov
>>> 2010) Log
>>>
>>>  -fixed potential multi-threading issues with static member variable initialization
>>>  -expose resip local logger id to applications
>>>
>>>
>>>
>>>
>>> Modified:
>>>
>>>    - main/resip/dum/UserProfile.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/dum/UserProfile.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/Contents.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/Contents.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/DnsInterface.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/DnsInterface.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/DnsResult.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/DnsResult.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/SdpContents.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/SdpContents.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/SipMessage.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/SipMessage.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/Tuple.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/Tuple.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/Uri.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/Uri.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/XMLCursor.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/XMLCursor.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/ssl/Security.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/ssl/Security.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/resip/stack/ssl/WinSecurity.cxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/resip/stack/ssl/WinSecurity.cxx?r1=8870&r2=8871&diff_format=l>
>>>    - main/rutil/Log.hxx
>>>    <http://svn.resiprocate.org/viewsvn/resiprocate/main/rutil/Log.hxx?r1=8870&r2=8871&diff_format=l>
>>>
>>>
>>> _______________________________________________
>>> resiprocate-commit mailing list
>>> resiprocate-commit at resiprocate.org
>>> https://list.resiprocate.org/mailman/listinfo/resiprocate-commit
>>>
>>
>>
>> _______________________________________________
>> resiprocate-devel mailing list
>> resiprocate-devel at resiprocate.org
>> https://list.resiprocate.org/mailman/listinfo/resiprocate-devel
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20101201/69b07611/attachment.htm>


More information about the resiprocate-devel mailing list