Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Apr 2015 18:53:27 +0530
From:      Dheeraj Kandula <dheerajktech@gmail.com>
To:        Mateusz Guzik <mjguzik@gmail.com>, Dheeraj Kandula <dheerajktech@gmail.com>, freebsd-hackers@freebsd.org
Subject:   Re: Clarification: Acquiring a mutex when a read/write lock is held
Message-ID:  <CAJ5QSa2MZ%2BHcLchPSZKhA9jw9vCrutQ0EVS3RpO7s4OvW=uU%2Bw@mail.gmail.com>
In-Reply-To: <20150421113914.GA6312@dft-labs.eu>
References:  <CAJ5QSa2ECN4c854nsg%2BJdZhXuskgb-pdzYkmop7B_3aSV=Zf7A@mail.gmail.com> <20150421113914.GA6312@dft-labs.eu>

next in thread | previous in thread | raw e-mail | index | archive | help
Thanks for the response. I want to acquire the read/write lock first either
as reader or writer and then acquire the mutex lock.
I think the second part of your response deals with ordering of locks to
prevent deadlock. That shouldn't be an issue. Thanks again for the quick
reply.

On Tue, Apr 21, 2015 at 5:09 PM, Mateusz Guzik <mjguzik@gmail.com> wrote:

> On Tue, Apr 21, 2015 at 04:33:24PM +0530, Dheeraj Kandula wrote:
> > Hey All,
> >        Can you clarify the following
> >
> > I have a read write lock locked. Next I want to acquire a mutex when the
> > read write lock is held. Is this allowed or not. As far as I can
> understand
> > from the "FreeBSD Kernel Developers Handbook" this operation is allowed
> in
> > FreeBSD9.0, 10.0 and further.
> >
> > But the read write lock cannot be held while sleeping. Doesn't this
> > contradict the above statement, as a thread will go to sleep if can't
> > acquire the mutex when another thread holds the mutex.
> >
> > Hence what sleep are we referring here. Is this sleep(unbounded sleep) or
> > the bounded sleep.
> >
>
> Both lock types allow bound sleep, so there is nothing preventing you
> from establishing the order either way.
>
> Of course then there is the quesiton whether these particular locks you
> have in mind can be taken in the order you want to take them.
>
> --
> Mateusz Guzik <mjguzik gmail.com>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5QSa2MZ%2BHcLchPSZKhA9jw9vCrutQ0EVS3RpO7s4OvW=uU%2Bw>