Patch to mutex.c
Neale.Ferguson@SoftwareAG-USA.com
Neale.Ferguson@SoftwareAG-USA.com
Wed Sep 20 07:54:00 GMT 2000
Title: Patch to mutex.c
I have been encountering problems with pthread_mutex_unlock(). For cases where the mutex kind is PTHREAD_MUTEX_ERRORCHECK_NP, when a lock is called it uses __pthread_alt_lock() which results in either a 1 or a non-zero address being placed in the mutex status field depending if there are more than one waiters I assume. pthread_mutex_unlock() checks that a) mutex is owned by calling thread and 2) the status of the mutex when anded with 1 is non-zero (i.e. something is waiting). However, if alt_lock() had placed an address in this status field and not a 1 then the check will fail and EPERM returned. I believe the routine should look like:
--- mutex.cÃÂ ÃÂ ÃÂ ÃÂ 2000/09/20 14:33:57ÃÂ ÃÂ ÃÂ ÃÂ 1.1
+++ mutex.cÃÂ ÃÂ ÃÂ ÃÂ 2000/09/20 14:48:01
@@ -169,11 +169,11 @@
ÃÂ ÃÂ ÃÂ ÃÂ }
ÃÂ ÃÂ ÃÂ ÃÂ mutex->__m_owner = NULL;
ÃÂ ÃÂ ÃÂ ÃÂ __pthread_unlock(&mutex->__m_lock);
ÃÂ ÃÂ ÃÂ ÃÂ return 0;
ÃÂ ÃÂ case PTHREAD_MUTEX_ERRORCHECK_NP:
-ÃÂ ÃÂ ÃÂ if (mutex->__m_owner != thread_self() || (mutex->__m_lock.__status & 1) == 0)
+ÃÂ ÃÂ ÃÂ if (mutex->__m_owner != thread_self() || mutex->__m_lock.__status == 0)
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ return EPERM;
ÃÂ ÃÂ ÃÂ ÃÂ mutex->__m_owner = NULL;
ÃÂ ÃÂ ÃÂ ÃÂ __pthread_alt_unlock(&mutex->__m_lock);
ÃÂ ÃÂ ÃÂ ÃÂ return 0;
ÃÂ ÃÂ case PTHREAD_MUTEX_TIMED_NP:
The programs that were crapping out are now working fine.
Comments?
More information about the Libc-alpha
mailing list