This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
objective-c mutex deallocation bug
- To: gcc-patches at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- Subject: objective-c mutex deallocation bug
- From: Chris Ball <cball at fmco dot com>
- Date: Tue, 28 Sep 1999 16:44:45 -0700
I have sent this patch before but it has never appeared
so here it goes again. If it is easier to give me cvs
write access I will be happy to check in the change
myself.
>Date: Wed, 26 May 1999 17:32:18 -0700
>To: egcs-bugs@egcs.cygnus.com
>From: Chris Ball <cball@fmco.com>
>Subject: objective-c mutex deallocation bug
>Cc: tmartin@fmco.com, yonas
>
>Problem Description:
> pthread_mutex_destroy() will fail or have undefined
> behaviour if called with a locked mutex.
>
> objc_mutex_deallocate() locks the mutex it is trying
> to release to establish ownership. This lock is not
> released before calling __objc_mutex_deallocate() in
> thr-posix.c.
>
> Results: All mutex deallocate/release calls fail
> under linux when using the posix thread
> library.
>
>
>Versions Found to have Problem:
> gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
> to
> gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
>
> and probably many older releases.
and now in gcc-2.95.1.
>
>Notes:
> The behaviour of pthread_mutex_destroy() was checked
> via man pages for solaris 2.6 and linux using the
> posix thread library version 0.7.
>
>
>Solution:
> This patch to thr-posix.c fixes the problem. This
> releases all locks on the mutex so that in the case
> of a recursive lock the pthread_mutex_destroy() call
> will be successful.
>
>
>diff -c output:
diff redone as -c3p...
*** thr-posix.c.old Thu Sep 23 07:19:12 1999
--- thr-posix.c.new Thu Sep 23 07:19:12 1999
*************** __objc_mutex_allocate(objc_mutex_t mutex
*** 145,150 ****
--- 145,164 ----
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
+ int count = 1;
+
+ /*
+ * Posix Threads specifically require that the thread be unlocked for
+ * pthread_mutex_destroy to work.
+ */
+
+ while ( count )
+ {
+ if (( count = pthread_mutex_unlock((pthread_mutex_t *)mutex->backend))
+ < 0 )
+ return -1;
+ }
+
if (pthread_mutex_destroy((pthread_mutex_t *)mutex->backend))
return -1;
ChangeLog entry:
Thu Sep 23 07:19:12 1999 Chris Ball <cball@fmco.com>
* thr-posix.c (__objc_mutex_deallocate): made deallocate work.
Chris.