From owner-freebsd-threads@FreeBSD.ORG Thu May 24 19:50:09 2012 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5EAB11065740 for ; Thu, 24 May 2012 19:50:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2E2F18FC18 for ; Thu, 24 May 2012 19:50:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q4OJo9Ha067898 for ; Thu, 24 May 2012 19:50:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q4OJo90g067897; Thu, 24 May 2012 19:50:09 GMT (envelope-from gnats) Resent-Date: Thu, 24 May 2012 19:50:09 GMT Resent-Message-Id: <201205241950.q4OJo90g067897@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Alexis Ballier Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B75191065670 for ; Thu, 24 May 2012 19:40:34 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 88DAF8FC1A for ; Thu, 24 May 2012 19:40:34 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q4OJeYYG078252 for ; Thu, 24 May 2012 19:40:34 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q4OJeYih078251; Thu, 24 May 2012 19:40:34 GMT (envelope-from nobody) Message-Id: <201205241940.q4OJeYih078251@red.freebsd.org> Date: Thu, 24 May 2012 19:40:34 GMT From: Alexis Ballier To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: threads/168317: libthr: posix_mutex_trylock does not work with a PTHREAD_MUTEX_ADAPTIVE_NP thread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2012 19:50:09 -0000 >Number: 168317 >Category: threads >Synopsis: libthr: posix_mutex_trylock does not work with a PTHREAD_MUTEX_ADAPTIVE_NP thread >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu May 24 19:50:08 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Alexis Ballier >Release: 9.0-RELEASE >Organization: Gentoo >Environment: FreeBSD fbsd 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: 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 #include #include #include 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 #include #include #include 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. >How-To-Repeat: Try the above testcases, or run glib-2.32.3 testsuite, or watch bailing out any glib based program using trylock. >Fix: I'm attaching a patch against head that sould fix this. Patch attached with submission follows: Index: lib/libthr/thread/thr_mutex.c =================================================================== --- lib/libthr/thread/thr_mutex.c (revision 235924) +++ lib/libthr/thread/thr_mutex.c (working copy) @@ -538,6 +538,7 @@ switch (PMUTEX_TYPE(m->m_flags)) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_ADAPTIVE_NP: ret = EBUSY; break; >Release-Note: >Audit-Trail: >Unformatted: