You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Ravi Inampudi <in...@roguewave.com> on 2006/08/02 00:02:42 UTC
SourcePro ed 3 - deadlock situation
Hello,
A customer ran into a deadlock situation using SourcePro ed 3 with locale specific code. In locale.h and locale.cpp, it is mentioned in the code that there was an attempt to fix a deadlock scenario. Source code snippets appended below. However, SourcePro ed 9 locale API seem to have been redesigned. Could it be assumed that this deadlock problem was addressed at some point? How difficult is it to port these changes to SourcePro ed 3?
Regards,
Ravi
> /ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/source/stdlib/locale.cpp:5
> 55
>
> if (__imp && __imp != _C_imp) {
> // HACK: we might (should?) be locked here but locale
> dtor
> // locks again - this despicable hack prevents a
> deadlock
> locale __loc (__imp);
> __loc._C_install_facet (__facet, __id);
> __loc._C_imp = 0; // set to 0 to prevent dtor from
> locking
> --__imp->_C_ref_count; // decrement manually
> }
>
> /ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/include/rw/_locale.h: 170
> ~locale () {
> // HACK: _C_imp should normally never be 0; internally, though,
> // it's set to 0 in locale::_C_make_facet to prevent a deadlock
> if (_C_imp && 0 == _RWSTD_ATOMIC_PREDECREMENT
> (_C_imp->_C_ref_count,
>
> _C_imp->_C_mutex))
> delete _C_imp;
> }
>
> /ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/include/rw/_locale.h: 510
> // same as above but not guarded; called during initialization
> // of the num_get<> and num_put<> facets (this is a hack)
> inline const locale::facet&
> locale::_C_unsafe_use_facet (const id &__id, bool __implicit, category
> __cat,
> __facet_maker_func __maker) const
> {
> _RWSTD_ASSERT (0 != _C_imp);
>
> const facet *__facet = _C_get_facet (__id);
>
> if (!__facet)
> __facet = _C_make_facet (__id, __implicit, __cat, __maker);
>
> _RWSTD_ASSERT (__facet);
>
> return *__facet;
> }
Re: SourcePro ed 3 - deadlock situation
Posted by Martin Sebor <se...@roguewave.com>.
Ravi Inampudi wrote:
> Hello,
>
> A customer ran into a deadlock situation using SourcePro ed 3 with locale specific code. In locale.h and locale.cpp, it is mentioned in the code that there was an attempt to fix a deadlock scenario. Source code snippets appended below. However, SourcePro ed 9 locale API seem to have been redesigned. Could it be assumed that this deadlock problem was addressed at some point?
Yes. The old locale implementation (prior to libstd 3) was known
to have serious thread sefety (as well as other) issues. We tried
to "fix" them (hack around them would be a more accurate description)
but in the end decided that a complete rewrite was a better approach.
> How difficult is it to port these changes to SourcePro ed 3?
Very difficult. I expect it would be easier to port SourcePro 3 to
a later version of libtsd.
Martin
>
> Regards,
> Ravi
>
>
>>/ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/source/stdlib/locale.cpp:5
>>55
>>
>> if (__imp && __imp != _C_imp) {
>> // HACK: we might (should?) be locked here but locale
>>dtor
>> // locks again - this despicable hack prevents a
>>deadlock
>> locale __loc (__imp);
>> __loc._C_install_facet (__facet, __id);
>> __loc._C_imp = 0; // set to 0 to prevent dtor from
>>locking
>> --__imp->_C_ref_count; // decrement manually
>> }
>>
>>/ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/include/rw/_locale.h: 170
>> ~locale () {
>> // HACK: _C_imp should normally never be 0; internally, though,
>> // it's set to 0 in locale::_C_make_facet to prevent a deadlock
>> if (_C_imp && 0 == _RWSTD_ATOMIC_PREDECREMENT
>>(_C_imp->_C_ref_count,
>>
>>_C_imp->_C_mutex))
>> delete _C_imp;
>> }
>>
>>/ms/dev/3rd/RWSourcePro/3.1/src/rw_buildspace/include/rw/_locale.h: 510
>>// same as above but not guarded; called during initialization
>>// of the num_get<> and num_put<> facets (this is a hack)
>>inline const locale::facet&
>>locale::_C_unsafe_use_facet (const id &__id, bool __implicit, category
>>__cat,
>> __facet_maker_func __maker) const
>>{
>> _RWSTD_ASSERT (0 != _C_imp);
>>
>> const facet *__facet = _C_get_facet (__id);
>>
>> if (!__facet)
>> __facet = _C_make_facet (__id, __implicit, __cat, __maker);
>>
>> _RWSTD_ASSERT (__facet);
>>
>> return *__facet;
>>}
>
>
>