Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Apr 2007 14:36:21 -0400 (EDT)
From:      Daniel Eischen <deischen@freebsd.org>
To:        Hans Petter Selasky <hselasky@freebsd.org>
Cc:        Attilio Rao <attilio@freebsd.org>, freebsd-hackers@freebsd.org, Julian Elischer <julian@elischer.org>
Subject:   Re: msleep() on recursivly locked mutexes
Message-ID:  <Pine.GSO.4.64.0704271426080.9587@sea.ntplx.net>
In-Reply-To: <200704271917.29939.hselasky@freebsd.org>
References:  <200704262136.33196.hselasky@c2i.net> <200704270748.49404.hselasky@c2i.net> <Pine.GSO.4.64.0704270906001.8536@sea.ntplx.net> <200704271917.29939.hselasky@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 27 Apr 2007, Hans Petter Selasky wrote:

> On Friday 27 April 2007 15:14, Daniel Eischen wrote:
>>
>> When you hold a mutex, it should be for a very short time.  And
>> I agree with the other comment that all drivers should be multi-thread
>> safe, so we shouldn't add cruft to allow for non MT-safe drivers.
>
> Yes, and no.
>
> Mutexes are used to get the CPU out of the code. Therefore you should not
> lock/unlock all the time, to ensure that the locked time is as short as
> possible. Because then you get double work checking the state after that you
> lock a mutex again. Surely, in a "static" environment there is nothing to
> check. But in a dynamic environment you need to check that "descriptors" of
> all kinds are still present, after that you lock a mutex. Unlocking a mutex
> allows "anything" to happen. Keeping a mutex locked prevents certain things
> from happening.

If you need to prevent "things" from happening, and it is at more
of a macro level than micro level, then you probably want a condvar
or barrier sort of synchroninzation, or possibly a rwlock.  When
the thread currently in the guts of your driver exits, he releases
the CV or rwlock and allows another thread to enter (which possibly
causes another "anything" to happen).

-- 
DE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0704271426080.9587>