public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-08-08 23:26 Loren James Rittle
  0 siblings, 0 replies; 12+ messages in thread
From: Loren James Rittle @ 2002-08-08 23:26 UTC (permalink / raw)
  To: ljrittle; +Cc: gcc-prs

The following reply was made to PR libstdc++/7445; it has been noted by GNATS.

From: Loren James Rittle <rittle@latour.rsch.comm.mot.com>
To: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
        gcc-prs@gcc.gnu.org, ljrittle@gcc.gnu.org, shurik@sequoiap.com
Cc:  
Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
Date: Thu, 8 Aug 2002 18:58:42 -0500 (CDT)

 OK, I'd be happy to find a performance fix that doesn't make the
 library code subtly less portable when we have a test case.  A
 reference to code already in our test suite would be acceptable.
 
 I just looked at some locale code in our test suite under gdb and then
 constructed the smallest cases that used std::locale::classic() [1]
 and another that did not [2].  Then, I compiled both [1] and [2] with
 and without -static and looked under gdb.  In all four cases,
 std::locale::classic() was called once before main().
 
 [1]
 #include <locale>
 
 int main (void)
 {
   std::locale::classic();
 }
 
 [2]
 #include <locale>
 
 int main (void)
 {
 }
 
 Benjamin (as the "local locale" expert), is it *always* true that
 std::locale::classic() is called at least once during startup before
 control is transferred to main()?  If so (and will always be so), then
 all thread-related locking could be removed IMHO.  In practice, our
 implementation of the Standard C++ library (with optional threading
 support) already supposes that no thread which uses the library
 implementation may have ever been started before main() is invoked.
 If not true, then this change would make a very hard to detect
 threading bug when the assumption changes.
 
 Regards,
 Loren


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 18:31 ljrittle
  0 siblings, 0 replies; 12+ messages in thread
From: ljrittle @ 2002-11-19 18:31 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, ljrittle, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

State-Changed-From-To: open->closed
State-Changed-By: ljrittle
State-Changed-When: Wed Nov 13 06:57:57 2002
State-Changed-Why:
    Patch applied to mainline.  Thank you for the report.
    Sorry for the lengthy delay in getting this sorted out.
    Should be safe for 3.2 branch when it reopens but we
    don't usually consider performance patches.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 18:27 bkoz
  0 siblings, 0 replies; 12+ messages in thread
From: bkoz @ 2002-11-19 18:27 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, ljrittle, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

State-Changed-From-To: closed->open
State-Changed-By: bkoz
State-Changed-When: Tue Nov 12 19:56:30 2002
State-Changed-Why:
    Loren, it looks like there is a test case for this now. Can you take a look at this please?
    
    thanks,
    benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 18:16 Alex Kompel
  0 siblings, 0 replies; 12+ messages in thread
From: Alex Kompel @ 2002-11-19 18:16 UTC (permalink / raw)
  To: ljrittle; +Cc: gcc-prs

The following reply was made to PR libstdc++/7445; it has been noted by GNATS.

From: "Alex Kompel" <shurik@sequoiap.com>
To: "Benjamin Kosnik" <bkoz@redhat.com>
Cc: <bkoz@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>,
   <ljrittle@gcc.gnu.org>, <gcc-gnats@gcc.gnu.org>
Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
Date: Tue, 12 Nov 2002 12:48:46 -0800

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0063_01C28A49.D6F2B070
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 > 
 > >I am a bit confused. Audit trail is kind of hard to read. Have you been
 > >waiting on something from me?
 > 
 > Uh. Yeah.
 > 
 > We need a test case. Provide one and we'll re-open this. I thought I'd
 > made this clear, but apparently not.
 > 
 
 See the attached file. 
 get_locale() is functionally equivalent to std::locale::classic()
 
 ----- test results (RedHat 7.3 2.4.18-17.7.xsmp 2 CPU -----
 [root@epos4 test]# c++ -DDO_LOCK -o test_lock -pthread loc_thr.cpp
 [root@epos4 test]# c++ -o test_nolock -pthread loc_thr.cpp
 [root@epos4 test]# ./test_lock
 Creating thread 0
 Creating thread 1
 Creating thread 2
 Creating thread 3
 Starting sorting...
 Sorting time:    4.08
 Sorting time:    4.02
 Sorting time:    4.26
 Sorting time:    4.21
 [root@epos4 test]# ./test_nolock
 Creating thread 0
 Creating thread 1
 Creating thread 2
 Creating thread 3
 Starting sorting...
 Sorting time:    0.06
 Sorting time:    0.06
 Sorting time:    0.06
 Sorting time:    0.06
 
 ------=_NextPart_000_0063_01C28A49.D6F2B070
 Content-Type: application/octet-stream;
 	name="loc_thr.cpp"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="loc_thr.cpp"
 
 #include <pthread.h>=0A=
 #include <locale>=0A=
 #include <string>=0A=
 #include <functional>=0A=
 #include <list>=0A=
 =0A=
 #define NUM_THREADS 4=0A=
 #define SORT_SIZE 1000=0A=
 #define NSAMPLES 5=0A=
 const char* samples[NSAMPLES] =3D {=0A=
 	"this is just a test 1",=0A=
 	"THIS IS JUST A TEST 1",=0A=
 	"this IS JUST A TEST 1",=0A=
 	"THIS IS JUST A TEST 2",=0A=
 	"this is just a test 2"=0A=
 };=0A=
 =0A=
 extern const std::locale& get_locale() {=0A=
       static const std::locale* l =3D 0;=0A=
 #ifdef DO_LOCK=0A=
       static std::_STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;=0A=
       std::_STL_auto_lock __auto(__lock);=0A=
       if( !l ) {=0A=
 	 l =3D &std::locale::classic();=0A=
       }=0A=
 #else=0A=
       if( !l ) {=0A=
          static std::_STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;=0A=
          std::_STL_auto_lock __auto(__lock);=0A=
 	 l =3D &std::locale::classic();=0A=
       }=0A=
 #endif=0A=
       return *l;=0A=
 }=0A=
 =0A=
 template <class T>=0A=
 bool lowercase_less( T c1, T c2 ) {=0A=
 	return std::tolower(c1, get_locale()) < std::tolower(c2, get_locale());=0A=
 }=0A=
 =0A=
 template <class T>=0A=
 bool str_case_less(const std::basic_string<T>& s1, const =
 std::basic_string<T>& s2)=0A=
 {=0A=
 	return std::lexicographical_compare(=0A=
 			s1.begin(), s1.end(),=0A=
 			s2.begin(), s2.end(),=0A=
 			std::ptr_fun( lowercase_less<T> )=0A=
 		 );=0A=
 }=0A=
 =0A=
 pthread_mutex_t count_mutex;=0A=
 pthread_cond_t ready_sort;=0A=
 int ready_count =3D 0;=0A=
 =0A=
 typedef std::list<std::string> test_list;=0A=
 void* thread_main( void* ) =0A=
 {=0A=
 	test_list tl;=0A=
 =0A=
 	for( int i=3D0; i<SORT_SIZE; i++ ) {=0A=
 		tl.push_back( samples[i%NSAMPLES] );=0A=
 	}=0A=
 =0A=
     	pthread_mutex_lock(&count_mutex);=0A=
 	if( ++ready_count<NUM_THREADS ) {=0A=
     		pthread_cond_wait(&ready_sort, &count_mutex);=0A=
 	} else {=0A=
 		printf( "Starting sorting...\n" );=0A=
 		pthread_cond_broadcast(&ready_sort);=0A=
 	}=0A=
     	pthread_mutex_unlock(&count_mutex);=0A=
 =0A=
 	clock_t t1, t2;=0A=
 	t1 =3D clock();=0A=
 	tl.sort( str_case_less<char> );=0A=
 	t2 =3D clock();=0A=
 	printf( "Sorting time: %7.2f\n", (float)(t2-t1)/CLOCKS_PER_SEC);=0A=
 	return 0;=0A=
 }=0A=
 =0A=
 =0A=
 int main()=0A=
 {=0A=
 	pthread_t thread[NUM_THREADS];=0A=
    	pthread_attr_t attr;=0A=
 	int t;=0A=
 =0A=
   	/* Initialize mutex and condition variable objects */=0A=
  	pthread_mutex_init(&count_mutex, NULL);=0A=
   	pthread_cond_init(&ready_sort, NULL);=0A=
 =0A=
    	/* Initialize and set thread detached attribute */=0A=
    	pthread_attr_init(&attr);=0A=
    	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);=0A=
 =0A=
    	for(t=3D0;t < NUM_THREADS;t++) {=0A=
       		printf("Creating thread %d\n", t);=0A=
       		pthread_create(&thread[t], &attr, thread_main, NULL); =0A=
    	}=0A=
 =0A=
    	/* Free attribute and wait for the other threads */=0A=
    	for(t=3D0;t < NUM_THREADS;t++) {=0A=
        		pthread_join(thread[t], NULL);=0A=
    	}=0A=
 =0A=
    	pthread_attr_destroy(&attr);=0A=
  	pthread_mutex_destroy(&count_mutex);=0A=
   	pthread_cond_destroy(&ready_sort);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
 
 ------=_NextPart_000_0063_01C28A49.D6F2B070--
 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 12:46 Benjamin Kosnik
  0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Kosnik @ 2002-11-19 12:46 UTC (permalink / raw)
  To: ljrittle; +Cc: gcc-prs

The following reply was made to PR libstdc++/7445; it has been noted by GNATS.

From: Benjamin Kosnik <bkoz@redhat.com>
To: "Alex Kompel" <shurik@sequoiap.com>
Cc: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   ljrittle@gcc.gnu.org, shurik@sequoiap.com, gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
Date: Mon, 11 Nov 2002 22:40:46 -0600

 >I am a bit confused. Audit trail is kind of hard to read. Have you been
 >waiting on something from me?
 
 Uh. Yeah.
 
 We need a test case. Provide one and we'll re-open this. I thought I'd
 made this clear, but apparently not.
 
 -benjamin


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 12:46 Alex Kompel
  0 siblings, 0 replies; 12+ messages in thread
From: Alex Kompel @ 2002-11-19 12:46 UTC (permalink / raw)
  To: ljrittle; +Cc: gcc-prs

The following reply was made to PR libstdc++/7445; it has been noted by GNATS.

From: "Alex Kompel" <shurik@sequoiap.com>
To: <bkoz@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>,
   <ljrittle@gcc.gnu.org>, <shurik@sequoiap.com>, <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
Date: Mon, 11 Nov 2002 18:52:18 -0800

 I am a bit confused. Audit trail is kind of hard to read. Have you been
 waiting on something from me?
 
 -alex
 
 ----- Original Message ----- 
 From: <bkoz@gcc.gnu.org>
 To: <gcc-bugs@gcc.gnu.org>; <gcc-prs@gcc.gnu.org>; <ljrittle@gcc.gnu.org>; <shurik@sequoiap.com>
 Sent: Monday, November 11, 2002 3:12 PM
 Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
 
 
 > Synopsis: poor performance of std::locale::classic() in multi-threaded applications
 > 
 > State-Changed-From-To: analyzed->closed
 > State-Changed-By: bkoz
 > State-Changed-When: Mon Nov 11 15:12:30 2002
 > State-Changed-Why:
 >     No more details are forthcoming on this issue. We've needed a test case for more than six months.
 >     
 >     Sorry,
 >     benjamin
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-11-19 12:31 bkoz
  0 siblings, 0 replies; 12+ messages in thread
From: bkoz @ 2002-11-19 12:31 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, ljrittle, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

State-Changed-From-To: analyzed->closed
State-Changed-By: bkoz
State-Changed-When: Mon Nov 11 15:12:30 2002
State-Changed-Why:
    No more details are forthcoming on this issue. We've needed a test case for more than six months.
    
    Sorry,
    benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-08-09  2:26 Benjamin Kosnik
  0 siblings, 0 replies; 12+ messages in thread
From: Benjamin Kosnik @ 2002-08-09  2:26 UTC (permalink / raw)
  To: ljrittle; +Cc: gcc-prs

The following reply was made to PR libstdc++/7445; it has been noted by GNATS.

From: Benjamin Kosnik <bkoz@redhat.com>
To: Loren James Rittle <rittle@latour.rsch.comm.mot.com>
Cc: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
   gcc-prs@gcc.gnu.org, ljrittle@gcc.gnu.org, shurik@sequoiap.com
Subject: Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
Date: Thu, 8 Aug 2002 23:18:57 -0700

 > OK, I'd be happy to find a performance fix that doesn't make the
 > library code subtly less portable when we have a test case.  A
 > reference to code already in our test suite would be acceptable.
 
 Yeah. This is kind of all hand-wavy at this point.
 
 > Benjamin (as the "local locale" expert), is it *always* true that
 > std::locale::classic() is called at least once during startup before
 > control is transferred to main()?  If so (and will always be so), then
 > all thread-related locking could be removed IMHO.  In practice, our
 > implementation of the Standard C++ library (with optional threading
 > support) already supposes that no thread which uses the library
 > implementation may have ever been started before main() is invoked.
 > If not true, then this change would make a very hard to detect
 > threading bug when the assumption changes.
 
 This is true. I would think the lock could then be removed? I'll let you
 figure out what to do with current sources. Thanks for the help.
 
 -benjamin


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-08-08 17:06 bkoz
  0 siblings, 0 replies; 12+ messages in thread
From: bkoz @ 2002-08-08 17:06 UTC (permalink / raw)
  To: bkoz, gcc-bugs, gcc-prs, ljrittle, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

Responsible-Changed-From-To: bkoz->ljrittle
Responsible-Changed-By: bkoz
Responsible-Changed-When: Thu Aug  8 15:49:18 2002
Responsible-Changed-Why:
    I'm going to assign this to you. When/if sourcecode is provided that demonstrates this problem, perhaps you could take a look at it.
    
    I'll revert to the last known good state for now.
    
    -benjamin
State-Changed-From-To: feedback->analyzed
State-Changed-By: bkoz
State-Changed-When: Thu Aug  8 15:49:18 2002
State-Changed-Why:
    Reverted, pending suggestion by Loren to have actual code to analyze the problem. You'll have to come up with a self-contained, hopefully minimal test case that clearly shows this problem.
    
    -benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-08-02  9:25 bkoz
  0 siblings, 0 replies; 12+ messages in thread
From: bkoz @ 2002-08-02  9:25 UTC (permalink / raw)
  To: bkoz, gcc-bugs, gcc-prs, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

State-Changed-From-To: closed->feedback
State-Changed-By: bkoz
State-Changed-When: Fri Aug  2 09:25:22 2002
State-Changed-Why:
    No, not fixed...

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-07-31 12:35 bkoz
  0 siblings, 0 replies; 12+ messages in thread
From: bkoz @ 2002-07-31 12:35 UTC (permalink / raw)
  To: bkoz, gcc-bugs, gcc-prs, nobody, shurik

Synopsis: poor performance of std::locale::classic() in multi-threaded applications

Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-By: bkoz
Responsible-Changed-When: Wed Jul 31 12:35:31 2002
Responsible-Changed-Why:
    Mine.
State-Changed-From-To: open->closed
State-Changed-By: bkoz
State-Changed-When: Wed Jul 31 12:35:31 2002
State-Changed-Why:
    Something similar checked in to gcc sources. Thanks!
    
    -benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7445


^ permalink raw reply	[flat|nested] 12+ messages in thread

* libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications
@ 2002-07-30 11:46 shurik
  0 siblings, 0 replies; 12+ messages in thread
From: shurik @ 2002-07-30 11:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7445
>Category:       libstdc++
>Synopsis:       poor performance of std::locale::classic() in multi-threaded applications
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 30 11:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Alex Kompel
>Release:        gcc version 3.1.1
>Organization:
>Environment:
RedHat Linux 7.3
>Description:
poor performance of std::locale::classic() in multi-threaded applications. std::locale:classic() is using _STL_auto_lock too extensively. It should only be used when the locale object is initialized. It does locks the mutex
on every call at present. See the fix below.
>How-To-Repeat:

>Fix:
*** libstdc++-v3/src/locale.old Tue Jul 30 11:31:01 2002
--- libstdc++-v3/src/locale.cc  Tue Jul 30 11:31:13 2002
***************
*** 285,294 ****
    locale::classic()
    {
      static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;
-     _STL_auto_lock __auto(__lock);

      if (!_S_classic)
        {
        try
          {
            // 26 Standard facets, 2 references.
--- 285,294 ----
    locale::classic()
    {
      static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;

      if (!_S_classic)
        {
+         _STL_auto_lock __auto(__lock);
        try
          {
            // 26 Standard facets, 2 references.
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-11-13 14:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08 23:26 libstdc++/7445: poor performance of std::locale::classic() in multi-threaded applications Loren James Rittle
  -- strict thread matches above, loose matches on Subject: below --
2002-11-19 18:31 ljrittle
2002-11-19 18:27 bkoz
2002-11-19 18:16 Alex Kompel
2002-11-19 12:46 Benjamin Kosnik
2002-11-19 12:46 Alex Kompel
2002-11-19 12:31 bkoz
2002-08-09  2:26 Benjamin Kosnik
2002-08-08 17:06 bkoz
2002-08-02  9:25 bkoz
2002-07-31 12:35 bkoz
2002-07-30 11:46 shurik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).