This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch ping


Hi Ian,

Well, one option would presumably be to try to find somewhere to stash
the mutex which would not cause an ABI compatibility problem.  For
example, perhaps we could add a new field to locale::_Impl in such a
way that no ABI problem was introduced.  If we could ensure that the
new field was at the end of the structure in memory, then presumably
we would be OK as long as nothing depends on the size of the
structure.  Unfortunately, I see that src/globals_locale.cc does
depend on the size of locale::_Impl, so that won't work.

Or another option would be to borrow an existing mutex, which would
not introduce any new dependencies.  Unfortunately, all the mutexes I
see are file static and can not be referenced.

Or another option would be to eliminate the possible memory leak in
some other way. The possibility of the memory leak arises because two
threads may call operator() on a __use_cache simultaneously. When
this happens, it is possible for both threads to test that
__caches[__i] is not set, and for both to set it to a new cache
object. In a preemptive threading model, the threads could switch
right at the assignment in _M_install_cache, so it seems theoretically
possible for the value stored in _M_caches[__index] to be confused by
a simultaneous assignment from two threads. I don't see this can be
safely avoided without using a mutex.


Thanks for the detailed analysis of the various theoretical options, I learned from it.

So the only options I see are to add a new exported symbol in
libstdc++ (which could be a mutex, or we could, e.g., move
locale::_Impl::_M_install_cache to locale.cc), or to not retain the
caches.


If by "not retaining" you mean, basically, not using the caching mechanism, it is not an option: basically is the only way to achieve performance and correctness in this area (barring a complete redesign according to a complete different "philosophy", i.e., using narrowing instead of widening, an approach that we don't like, in a nutshell). Therefore, we need mutual exclusion. I'm under the impression that a smaller reorganization, moving code dealing with those mutexes to one of the *.cc files is by far the preferred option, consistent with the rest of the library: are you willing to get into the details of that? I could certainly help.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]