From: Programmingkid <programmingkidx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Help with deadlock when using sound
Date: Wed, 13 May 2015 09:54:25 -0400 [thread overview]
Message-ID: <65431E2C-2705-4E9A-A36C-9530D8658FCE@gmail.com> (raw)
In-Reply-To: <CAFEAcA8XyjgpHz0i0nprHKkP2Genh=Z2+D7qAeOawrZzFSZzYg@mail.gmail.com>
On May 13, 2015, at 5:38 AM, Peter Maydell wrote:
> On 13 May 2015 at 04:23, Programmingkid <programmingkidx@gmail.com> wrote:
>> Found out why QEMU is deadlocking. It is because a mutex that has been
>> unlocked over 20 times in a row is being locked.
>
> OSX supports 'error checking' mutexes which will fail in these
> undefined-behaviour cases like double-unlock. (The error checking
> slows things down which is why it's not the default). If you make
> qemu_mutex_init() something like:
>
> void qemu_mutex_init(QemuMutex *mutex)
> {
> int err;
> pthread_mutexattr_t mta;
>
> err = pthread_mutexattr_init(&mta);
> if (err) {
> error_exit(err, __func__);
> }
> err = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
> if (err) {
> error_exit(err, __func__);
> }
> err = pthread_mutex_init(&mutex->lock, &mta);
> if (err) {
> error_exit(err, __func__);
> }
> pthread_mutexattr_destroy(&mta);
> if (err) {
> error_exit(err, __func__);
> }
> }
>
> then we'll turn on the error checking, and a double-unlock
> will result in a call to abort(). If you run QEMU under
> a debugger you'll get a backtrace which will tell you which
> code did the second unlock (and thus which mutex it is).
>
> (Linux has a similar attribute, though it is named
> PTHREAD_MUTEX_ERRORCHECK_NP; we might want to consider
> turning on mutex debugging for --enable-debug builds.)
>
> -- PMM
Thanks for the code, but it didn't work as it was expected to. The abort or stack trace never happened. I did recompile using enable-debug.
next prev parent reply other threads:[~2015-05-13 13:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 16:40 [Qemu-devel] Help with deadlock when using sound Programmingkid
2015-05-06 17:00 ` Peter Maydell
2015-05-06 19:41 ` Programmingkid
2015-05-06 21:10 ` Peter Maydell
2015-05-06 21:19 ` Programmingkid
2015-05-06 21:31 ` Peter Maydell
2015-05-06 21:41 ` Programmingkid
2015-05-06 21:53 ` Peter Maydell
2015-05-06 21:30 ` Programmingkid
2015-05-10 14:54 ` Paolo Bonzini
2015-05-10 15:55 ` Paolo Bonzini
2015-05-10 19:41 ` Programmingkid
2015-05-11 22:43 ` Programmingkid
2015-05-12 7:45 ` Paolo Bonzini
2015-05-12 18:59 ` Programmingkid
2015-05-13 3:23 ` Programmingkid
2015-05-13 9:38 ` Peter Maydell
2015-05-13 13:54 ` Programmingkid [this message]
2015-05-13 15:03 ` Peter Maydell
2015-05-13 13:56 ` Paolo Bonzini
[not found] <BDB13C47-556C-4C58-8A4C-2BB7343F1FB4@gmail.com>
2015-05-10 14:05 ` Programmingkid
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=65431E2C-2705-4E9A-A36C-9530D8658FCE@gmail.com \
--to=programmingkidx@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).