I discovered this running glib-2.32.3 testsuite. If I feed pthread_mutex_trylock with a PTHREAD_MUTEX_ADAPTIVE_NP thread, it returns EINVAL instead of EBUSY if it fails to lock. Reduced testcase: # cat mutex.c #include <stdlib.h> #include <stdio.h> #include <string.h> #include <pthread.h> int main() { pthread_mutex_t mutex; pthread_mutexattr_t attr; int status; pthread_mutexattr_init (&attr); pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP); status = pthread_mutex_init (&mutex, &attr); printf("status = %i\n", status); status = pthread_mutex_trylock(&mutex); printf("status = %i\n", status); status = pthread_mutex_trylock(&mutex); printf("status = %i\n", status); printf("%s\n", strerror(status)); } # gcc -pthread mutex.c -o mutex # ./mutex status = 0 status = 0 status = 22 Invalid argument However, with a PTHREAD_MUTEX_NORMAL thread it is fine: # cat mutex2.c #include <stdlib.h> #include <stdio.h> #include <string.h> #include <pthread.h> int main() { pthread_mutex_t mutex; pthread_mutexattr_t attr; int status; pthread_mutexattr_init (&attr); pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_NORMAL); status = pthread_mutex_init (&mutex, &attr); printf("status = %i\n", status); status = pthread_mutex_trylock(&mutex); printf("status = %i\n", status); status = pthread_mutex_trylock(&mutex); printf("status = %i\n", status); printf("%s\n", strerror(status)); } # gcc -pthread mutex2.c -o mutex2 # ./mutex2 status = 0 status = 0 status = 16 Device busy Some investigation showed that svn rev 173154 got that right but then svn rev 173173 removed this. Fix: I'm attaching a patch against head that sould fix this. Patch attached with submission follows: How-To-Repeat: Try the above testcases, or run glib-2.32.3 testsuite, or watch bailing out any glib based program using trylock.
Thanks for find it! We have been using this patch to get the glib works. http://www.marcuscom.com:8080/cgi-bin/cvsweb.cgi/ports-experimental/devel/glib20/files/patch-glib_gthread-posix.c Cheers, Mezz -- mezz.freebsd@gmail.com - mezz@FreeBSD.org FreeBSD GNOME Team http://www.FreeBSD.org/gnome/ - gnome@FreeBSD.org
Author: davidxu Date: Sun May 27 01:24:51 2012 New Revision: 236135 URL: http://svn.freebsd.org/changeset/base/236135 Log: Return EBUSY for PTHREAD_MUTEX_ADAPTIVE_NP too when the mutex could not be acquired. PR: 168317 MFC after: 3 days Modified: head/lib/libthr/thread/thr_mutex.c Modified: head/lib/libthr/thread/thr_mutex.c ============================================================================== --- head/lib/libthr/thread/thr_mutex.c Sun May 27 01:24:08 2012 (r236134) +++ head/lib/libthr/thread/thr_mutex.c Sun May 27 01:24:51 2012 (r236135) @@ -538,6 +538,7 @@ mutex_self_trylock(struct pthread_mutex switch (PMUTEX_TYPE(m->m_flags)) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_ADAPTIVE_NP: ret = EBUSY; break; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Author: davidxu Date: Wed May 30 01:52:53 2012 New Revision: 236275 URL: http://svn.freebsd.org/changeset/base/236275 Log: MFC r236135: Return EBUSY for PTHREAD_MUTEX_ADAPTIVE_NP too when the mutex could not be acquired. PR: 168317 Modified: stable/9/lib/libthr/thread/thr_mutex.c Directory Properties: stable/9/lib/libthr/ (props changed) Modified: stable/9/lib/libthr/thread/thr_mutex.c ============================================================================== --- stable/9/lib/libthr/thread/thr_mutex.c Wed May 30 01:52:01 2012 (r236274) +++ stable/9/lib/libthr/thread/thr_mutex.c Wed May 30 01:52:53 2012 (r236275) @@ -538,6 +538,7 @@ mutex_self_trylock(struct pthread_mutex switch (PMUTEX_TYPE(m->m_flags)) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_ADAPTIVE_NP: ret = EBUSY; break; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Author: davidxu Date: Wed May 30 01:54:14 2012 New Revision: 236276 URL: http://svn.freebsd.org/changeset/base/236276 Log: MFC r236135: Return EBUSY for PTHREAD_MUTEX_ADAPTIVE_NP too when the mutex could not be acquired. PR: 168317 Modified: stable/8/lib/libthr/thread/thr_mutex.c Directory Properties: stable/8/lib/libthr/ (props changed) Modified: stable/8/lib/libthr/thread/thr_mutex.c ============================================================================== --- stable/8/lib/libthr/thread/thr_mutex.c Wed May 30 01:52:53 2012 (r236275) +++ stable/8/lib/libthr/thread/thr_mutex.c Wed May 30 01:54:14 2012 (r236276) @@ -484,6 +484,7 @@ mutex_self_trylock(struct pthread_mutex switch (m->m_type) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_ADAPTIVE_NP: ret = EBUSY; break; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
State Changed From-To: open->closed Fixed!
A commit references this bug: Author: jbeich Date: Tue Mar 28 09:48:24 UTC 2017 New revision: 437111 URL: https://svnweb.freebsd.org/changeset/ports/437111 Log: devel/glib20: drop adaptive mutex workaround PR: 168317 Changes: head/devel/glib20/Makefile head/devel/glib20/files/patch-glib_gthread-posix.c