On Thu, Sep 6, 2012 at 12:16 PM, Martin Sebor <[email protected]> wrote:
> This locks a different mutex, one unrelated to __rw_facet::_C_mutex.
Let's debug this the good-ol' fashioned way: with fprintf(3C). Let's
print the addresses of the mutex being locked in various places, and
see what we get:
1. include/loc/_numpunct.h:
template <class _CharT>
inline string numpunct<_CharT>::grouping () const
{
if (!(_C_flags & _RW::__rw_gr)) {
numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
// ###
(void) fprintf(stderr,
"%s: _RWSTD_MT_GUARD (__self->_C_mutex): 0x%x\n",
__func__, (void *) &(__self->_C_mutex));
// ###
_RWSTD_MT_GUARD (__self->_C_mutex);
if (!(_C_flags & _RW::__rw_gr)) {
// [try to] get the grouping first (may throw)
// then set a flag to avoid future initializations
__self->_C_grouping = do_grouping ();
__self->_C_flags |= _RW::__rw_gr;
}
}
return _C_grouping;
}
2. src/facet.cpp:
const void* __rw_facet::_C_get_data ()
{
// check initialization
if (_C_impsize)
return _C_impdata;
// `pid' may be 0 if the facet has not been obtained
// by a call to use_facet (but instead constructed
// and used directly without having been installed
// in a locale object); in that case, locale database
// mapping for the facet is not available
if (!_C_pid)
return _C_impdata;
(void) fprintf(stderr, "%s: _RWSTD_MT_GUARD (&_C_mutex): 0x%x\n",
__func__, (void *) &_C_mutex);
// lock the object
_RWSTD_MT_GUARD (&_C_mutex);
[ ... ]
And now let's run it:
[steleman@darthvader][/src/steleman/programming/stdcxx-ss122/stdcxx-4.2.1/build/tests][09/06/2012
14:40:11][1084]>> ./22.locale.numpunct.mt --nthreads=2 --nloops=100
# INFO (S1) (10 lines):
# TEXT:
# COMPILER: SunPro, __SUNPRO_CC = 0x5120
# ENVIRONMENT: i386 running linux (Fedora release 17 (Beefy Miracle)
(3.5.0-2.fc17.x86_64)) with glibc 2.15
# FILE: 22.locale.numpunct.mt.cpp
# COMPILED: Sep 6 2012, 14:38:42
# COMMENT: thread safety
############################################################
# CLAUSE: lib.locale.numpunct
# NOTE (S2) (5 lines):
# TEXT: executing "/usr/bin/locale -a > /tmp/tmpfile-YzXcb9"
# CLAUSE: lib.locale.numpunct
# FILE: process.cpp
# LINE: 276
grouping: _RWSTD_MT_GUARD (__self->_C_mutex): 0xf774913c
_C_get_data: _RWSTD_MT_GUARD (&_C_mutex): 0xf774913c
[ ... deadlock ... ]
Looks like the same mutex to me ...
--Stefan
--
Stefan Teleman
KDE e.V.
[email protected]