From owner-freebsd-threads@FreeBSD.ORG Sat Dec 6 09:51:44 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9AE6C16A4CE for ; Sat, 6 Dec 2003 09:51:44 -0800 (PST) Received: from park.rambler.ru (park.rambler.ru [81.19.64.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 45A7143FF2 for ; Sat, 6 Dec 2003 09:51:42 -0800 (PST) (envelope-from is@rambler-co.ru) Received: from is (is.park.rambler.ru [81.19.64.102]) by park.rambler.ru (8.12.6/8.12.6) with ESMTP id hB6HpeWU003359 for ; Sat, 6 Dec 2003 20:51:40 +0300 (MSK) (envelope-from is@rambler-co.ru) Date: Sat, 6 Dec 2003 20:51:40 +0300 (MSK) From: Igor Sysoev X-Sender: is@is To: threads@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: pthread_mutex_trylock() should never block X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Dec 2003 17:51:44 -0000 The current pthread_mutex_trylock() implementation in both libpthread (libkse) and libthr can block if mutex is locked by another thread. libphtread calls THR_LOCK_ACQUIRE() and it can be blocked. libthr's pthread_mutex_trylock() is too heavy - it calls 3 syscalls: sigprocmask()/umtx_lock()/sigprocmask() and can be blocked too. SUSv2 states: [ http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html ] -------- The function pthread_mutex_trylock() is identical to pthread_mutex_lock() except that if the mutex object referenced by mutex is currently locked (by any thread, including the current thread), the call returns immediately. [ ... ] The pthread_mutex_trylock() function will fail if: [EBUSY] The mutex could not be acquired because it was already locked. [ ... ] The pthread_mutex_lock() function may fail if: [EDEADLK] The current thread already owns the mutex. -------- Igor Sysoev http://sysoev.ru/en/