From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11833 invoked by alias); 19 Jan 2002 15:37:40 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 11778 invoked from network); 19 Jan 2002 15:37:34 -0000 Received: from unknown (HELO mta05-svc.ntlworld.com) (62.253.162.45) by sources.redhat.com with SMTP; 19 Jan 2002 15:37:34 -0000 Received: from garfield.andypo.net ([80.3.248.119]) by mta05-svc.ntlworld.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020119153733.PVXI7206.mta05-svc.ntlworld.com@garfield.andypo.net> for ; Sat, 19 Jan 2002 15:37:33 +0000 Received: (from andrewp@localhost) by garfield.andypo.net (8.11.6/8.8.7) id g0JFZD517204; Sat, 19 Jan 2002 15:35:13 GMT Date: Sun, 20 Jan 2002 03:13:00 -0000 Message-Id: <200201191535.g0JFZD517204@garfield.andypo.net> From: Andrew Pollard To: gcc@gcc.gnu.org In-reply-to: <61170000.1011164839@warlock.codesourcery.com> (message from Mark Mitchell on Tue, 15 Jan 2002 23:07:19 -0800) Subject: Re: Plans for 3.0.4 ? (Re: new PR libstdc++/5432) References: <61170000.1011164839@warlock.codesourcery.com> X-SW-Source: 2002-01/txt/msg01333.txt.bz2 Mark Mitchell wrote: >> What (if any) are the plans for a 3.0.4 release of gcc? > I've been deliberately noncommittal, but it's time to commit, I guess. > > So, this is a poll: how many people feel that a 3.0.4 release > would be valuable? I would like to see a 3.0.4 release, hopefully fixing the libstdc++/5432 report that I have just submitted (related to libstdc++/5347 and libstdc++/5037 - multithreading issues on multiprocessor machines). I attempted to attach a test program and a tentative patch to the problem report, but only the patch made it :-( I'm including the test program here in the hope that someone with the right access can update the gnats report to include this as well.... I'm also including the patch here (which attempts to address some of the "XXX MT" issues in the libstdc++ source code) which seems to 'fix' the problems... main.cxx ------------------------------------------------------------------------------ #include #include const size_t num_threads = 4; extern "C" { static void* threadFunc(void*) { for (size_t i = 0; i < 10000; ++i) { std::stringstream str; } pthread_exit(0); return(0); } } int main() { pthread_t threads[num_threads]; #if !defined(__linux__) thr_setconcurrency(num_threads); #endif for (size_t i = 0; i < num_threads; ++i) { pthread_create(&(threads[i]), 0, threadFunc, 0); } for (size_t i = 0; i < num_threads; ++i) { pthread_join(threads[i], 0); } pthread_exit(0); return (0); } ------------------------------------------------------------------------------ patch ------------------------------------------------------------------------------ Index: include/bits/ios_base.h =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ios_base.h,v retrieving revision 1.8.2.3 diff -u -r1.8.2.3 ios_base.h --- ios_base.h 2001/06/06 01:39:00 1.8.2.3 +++ ios_base.h 2002/01/17 12:53:38 @@ -36,6 +36,8 @@ #pragma GCC system_header +#include + namespace std { // The following definitions of bitmask types are enums, not ints, @@ -239,17 +241,17 @@ _Callback_list* _M_next; ios_base::event_callback _M_fn; int _M_index; - int _M_refcount; // 0 means one reference. + _Atomic_word _M_refcount; // 0 means one reference. _Callback_list(ios_base::event_callback __fn, int __index, _Callback_list* __cb) : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } void - _M_add_reference() { ++_M_refcount; } // XXX MT + _M_add_reference() { __atomic_add(&_M_refcount, 1); } // XXX MT int - _M_remove_reference() { return _M_refcount--; } // 0 => OK to delete + _M_remove_reference() { return __exchange_and_add(&_M_refcount, -1); } // 0 => OK to delete }; _Callback_list* _M_callbacks; Index: include/bits/localefwd.h =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/localefwd.h,v retrieving revision 1.11.2.3 diff -u -r1.11.2.3 localefwd.h --- localefwd.h 2001/05/14 19:49:03 1.11.2.3 +++ localefwd.h 2002/01/17 12:53:38 @@ -43,6 +43,8 @@ #include // For isspace, etc. #include +#include + namespace std { // NB: Don't instantiate required wchar_t facets if no wchar_t support. @@ -307,7 +309,7 @@ private: // Data Members. - size_t _M_references; + _Atomic_word _M_references; __vec_facet* _M_facets; string _M_names[_S_num_categories]; __c_locale _M_c_locale; @@ -321,12 +323,12 @@ inline void _M_add_reference() throw() - { ++_M_references; } // XXX MT + { __atomic_add(&_M_references, 1); } // XXX MT inline void _M_remove_reference() throw() { - if (_M_references-- == 0) // XXX MT + if (__exchange_and_add(&_M_references, -1) == 0) // XXX MT { try { delete this; } @@ -394,7 +396,7 @@ _S_destroy_c_locale(__c_locale& __cloc); private: - size_t _M_references; + _Atomic_word _M_references; void _M_add_reference() throw(); @@ -428,7 +430,7 @@ mutable size_t _M_index; // Last id number assigned - static size_t _S_highwater; + static _Atomic_word _S_highwater; void operator=(const id&); // not defined Index: src/ios.cc =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v retrieving revision 1.14.4.2 diff -u -r1.14.4.2 ios.cc --- ios.cc 2001/06/06 01:39:01 1.14.4.2 +++ ios.cc 2002/01/17 12:53:38 @@ -36,6 +36,8 @@ #include #include +#include + namespace std { // Extern declarations for global objects in src/globals.cc. @@ -216,8 +218,8 @@ { // XXX MT // XXX should be a symbol. (Reserve 0..3 for builtins.) - static int top = 4; - return top++; + static _Atomic_word top = 4; + return __exchange_and_add(&top, 1); } // 27.4.2.5 iword/pword storage Index: src/locale.cc =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v retrieving revision 1.28.2.5 diff -u -r1.28.2.5 locale.cc --- locale.cc 2001/12/11 08:01:24 1.28.2.5 +++ locale.cc 2002/01/17 12:53:39 @@ -41,6 +41,8 @@ # include // for towupper, etc. #endif +#include + namespace std { // Definitions for static const data members of locale. @@ -68,7 +70,7 @@ #endif // Definitions for static const data members of locale::id - size_t locale::id::_S_highwater; // init'd to 0 by linker + _Atomic_word locale::id::_S_highwater; // init'd to 0 by linker // Definitions for static const data members of locale::_Impl const locale::id* const @@ -445,6 +447,9 @@ locale::classic() { static locale* __classic_locale; + static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER; + _STL_auto_lock __auto(__lock); + // XXX MT if (!_S_classic) { @@ -523,15 +528,13 @@ void locale::facet:: _M_add_reference() throw() - { ++_M_references; } // XXX MT + { __atomic_add(&_M_references, 1); } // XXX MT void locale::facet:: _M_remove_reference() throw() { - if (_M_references) - --_M_references; - else + if (__exchange_and_add(&_M_references, -1) == 0) { try { delete this; } // XXX MT Index: src/localename.cc =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/src/localename.cc,v retrieving revision 1.12.2.2 diff -u -r1.12.2.2 localename.cc --- localename.cc 2001/05/14 19:49:15 1.12.2.2 +++ localename.cc 2002/01/17 12:53:39 @@ -173,7 +173,7 @@ { size_t& __index = __idp->_M_index; if (!__index) - __index = ++locale::id::_S_highwater; // XXX MT + __index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1); // XXX MT if (__index >= _M_facets->size()) _M_facets->resize(__index + 1, 0); // might throw ------------------------------------------------------------------------------ Andrew. -- Andrew Pollard, ASI/Brooks Automation | home: andrew@andypo.net 670 Eskdale Road, Winnersh Triangle, UK | work: Andrew.Pollard@brooks.com Tel/Fax:+44 (0)118 9215603 / 9215660 | http://www.andypo.net