All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Geoffrey McRae <geoff@hostfission.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: recursive locks (in general)
Date: Fri, 21 Aug 2020 17:25:12 +0200	[thread overview]
Message-ID: <3505776.nlAjVYSdU6@silver> (raw)
In-Reply-To: <87c93055-c4ef-cba7-43b4-da2e7f65f2e4@redhat.com>

On Freitag, 21. August 2020 15:08:09 CEST Paolo Bonzini wrote:
> On 21/08/20 13:12, Christian Schoenebeck wrote:
> > There is a golden rule with recursive locks: You always have to preserve a
> > clear hierarchy. Say you have the following recursive mutexes:
> > 
> > RecursiveMutex mutex0;
> > RecursiveMutex mutex1;
> > RecursiveMutex mutex2;
> > ...
> > RecursiveMutex mutexN;
> > 
> > where the suffix shall identify the hierarchy, i.e. h(mutex0) = 0,
> > h(mutex1) = 1, ... h(mutexN) = N. Then the golden rule is that in any call
> > stack the nested locks must always preserve the same transitive hierarchy,
> 
> > e.g.:
> That's also what you do with regular locks.

You can't do that with non-recursive mutexes if you have cyclic dependencies.

> But the difference is that with regular locks you can always do
> 
> void bar(std::unique_lock<std::mutex> &mutex3_guard)
> {
> 	...
> 	mutex3_guard.unlock();
> 	synchronized(mutex2) {
> 	}
> 	mutex3_guard.lock();
> 	...
> }

Right, if you are able to clearly judge that this unlock is really safe for 
all layers involved.

Okay never mind, I see that we'll keep split on this recursive lock issue 
anyway. Sorry for the noise Paolo! :)

Best regards,
Christian Schoenebeck




  reply	other threads:[~2020-08-21 15:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19  6:29 [PATCH v5 0/1] audio/jack: fix use after free segfault Geoffrey McRae
2020-08-19  6:29 ` [PATCH v5 1/1] " Geoffrey McRae
2020-08-19 15:21   ` Christian Schoenebeck
2020-08-19 15:27     ` Geoffrey McRae
2020-08-20  5:37     ` Gerd Hoffmann
2020-08-20 10:06       ` Christian Schoenebeck
2020-08-20 10:54         ` Paolo Bonzini
2020-08-20 12:00           ` Christian Schoenebeck
2020-08-21 13:13             ` Paolo Bonzini
2020-08-26 13:48               ` PTHREAD_MUTEX_ERRORCHECK and fork() Christian Schoenebeck
2020-08-21 11:12           ` recursive locks (in general) Christian Schoenebeck
2020-08-21 13:08             ` Paolo Bonzini
2020-08-21 15:25               ` Christian Schoenebeck [this message]
2020-08-21 11:28           ` [PATCH v5 1/1] audio/jack: fix use after free segfault Geoffrey McRae
2020-08-21 13:13             ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3505776.nlAjVYSdU6@silver \
    --to=qemu_oss@crudebyte.com \
    --cc=geoff@hostfission.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.