From owner-freebsd-current@FreeBSD.ORG Sat Jan 24 23:14:57 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ACDAE1065677; Sat, 24 Jan 2009 23:14:57 +0000 (UTC) (envelope-from prvs=julian=268335b7e@elischer.org) Received: from smtp-outbound.ironport.com (smtp-outbound.ironport.com [63.251.108.112]) by mx1.freebsd.org (Postfix) with ESMTP id 8F6628FC0C; Sat, 24 Jan 2009 23:14:57 +0000 (UTC) (envelope-from prvs=julian=268335b7e@elischer.org) Received: from unknown (HELO julian-mac.elischer.org) ([10.251.60.85]) by smtp-outbound.ironport.com with ESMTP; 24 Jan 2009 15:14:55 -0800 Message-ID: <497BA0F2.5080004@elischer.org> Date: Sat, 24 Jan 2009 15:14:58 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 To: Maksim Yevmenkin References: <20090123154336.GJ60948@e.0x20.net> <200901232337.05627.hselasky@c2i.net> <200901240952.21670.hselasky@c2i.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org, current@freebsd.org, Alfred Perlstein , Hans Petter Selasky Subject: Re: panic: mutex Giant not owned at /usr/src/sys/kern/tty_ttydisc.c:1127 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jan 2009 23:14:58 -0000 Maksim Yevmenkin wrote: > Hans Petter, >> Do mutexes sleep? No? So my code should be fine? > > yes, regular mutexes sleep. Yes and no. This is a semantic thing.. They don't actually 'sleep', but they do deschedule the thread. the difference is purely semantic. Users of mutexes "agree" to never do anything that in indeterminately long while holding the mutex so you are SUPPOSED to get control back in a "short" period of time. Even if multiple mutexes have dependencies on each other, the fact that none of them may wait for a "long" time is suposed to guarantee that your thread should get control again "shortly". It is illegal to sleep while holding a mutex. This helps enforce this (otherwise small) distinction. A Sleep may wait for an arbitrary amount of time.. e.g. until reboot. so doing so with a mutex held would break the agreement. Effectively the only real difference is that the agreement by users to not use a mutex when things may get slow. Spin locks are even more strict.. BTW A mutex that is waiting on a thread on another processor may spin for a short amount of time before taking the expensive step of descheduling the thread.