From owner-freebsd-threads@FreeBSD.ORG Sat Dec 6 17:14:54 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 C6EE216A4CE; Sat, 6 Dec 2003 17:14:54 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B9BD43F75; Sat, 6 Dec 2003 17:14:54 -0800 (PST) (envelope-from davidxu@freebsd.org) Received: from freebsd.org (davidxu@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id hB71EqFY066062; Sat, 6 Dec 2003 17:14:53 -0800 (PST) (envelope-from davidxu@freebsd.org) Message-ID: <3FD27FC3.6020100@freebsd.org> Date: Sun, 07 Dec 2003 09:17:55 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.5) Gecko/20031206 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Daniel Eischen References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: deischen@freebsd.org cc: threads@freebsd.org Subject: Re: 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: Sun, 07 Dec 2003 01:14:54 -0000 Daniel Eischen wrote: >On Sat, 6 Dec 2003, Daniel Eischen wrote: > > > >>On Sat, 6 Dec 2003, Igor Sysoev wrote: >> >> >>>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 low-level locks are necessary (at least in libpthread implementation) >>to safely test the mutex for ownership. >> >> > >And not only that, but the low-level locks are also necessary to take >the mutex if it is not owned. > > > In libkse, if a thread is in critical region, scheduler will let it run until it leaves critical region unless it is blocked in kernel or volunteerly switchouts itself. In the case you are talking about, the thread will never be blocked on a UP machine. This only happens under SMP. David Xu