Necessity of __gthread_mutex_trylock

Wu Yongwei adah@netstd.com
Thu Feb 26 02:01:00 GMT 2004


What I meant was that if __gthread_mutex_trylock is not needed, on Win32
(specifically, Windows 9x) "We might consider using Critical Sections
instead of Windows32 mutexes for better performance". Currently, in
order to support __gthread_mutex_trylock, Win32 Mutex is used, which
incurs much more overhead than Critial Section. Critial Section is more
like the POSIX pthread_mutex_t, and is more efficient when locking does
not occur, but Windows 9x only provides EnterCriticalSection and
LeaveCriticalSection, but not TryEnterCriticalSection, which is needed
to emulate __gthread_mutex_trylock using Critical Section.

I once sent a patch to the mingw-dvlpr list, but was (correctly)
rejected by Danny just because I used TryEnterCriticalSection, which
is not supported on Win9x platforms. You may still find it at

http://article.gmane.org/gmane.comp.gnu.mingw.devel/799

According to my tests, the performance difference is really huge (600/9
in instructions, according to Microsoft). For example, repeating
50,000,000 times allocate/deallocate of the SGI alloc (__alloc in
libstdc++-v3) on my Celeron 550 MHz takes:

1 s, in mingw gcc 2.95.3-8 (default single-threaded)
8 s, in mingw gcc 2.95.3-8 (-mthreads, using critical sections)
5 s, in mingw gcc 3.2.3 (default single-threaded)
323 s, in mingw gcc 3.2.3 (-mthreads, using Win32 mutexes)

The 5/1 difference seems mainly caused by non-inlining in libstdc++-v3
(which also gives me doubts; and the test results in GCC 3.3 is even
worse, but I'll leave it form later discussions), but the 323/8
difference seems completely controlled by MUTEX/CRITICAL_SECTION.

Best regards,

Wu Yongwei

--- Original Message from Benjamin Kosnik ---

>However, grepping the GCC source and find no reference to
>__gthread_mutex_trylock except the gthr-* headers, I see no real use of
>it. Is it really necessary? Remove it and Win32 multi-threaded can
>behave better.

I also don't see any use of __gthread_mutex_trylock.

When you say "remove it and Win32 multi-threaded can behave better" what
do you mean, exactly? If possible, explain what you mean with a patch.

Just curious.

-benjamin





More information about the Libstdc++ mailing list