mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Edward Scott <ed@iotechsys.com>
To: musl@lists.openwall.com
Subject: [musl] Bug with priority inheritance and condition variables
Date: Thu, 24 Sep 2020 15:58:17 +0100	[thread overview]
Message-ID: <CANGYPwMccU6RFsSVvjnxQJCjG1_=oEYOVdYg5GwMrShr=oy7fw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]

Hello,

There appears to be a bug when using priority inheritance in combination
with condition variables. I have some code that reproduces the bug:

https://github.com/edward-scott/musl-prio-inherit-cv-bug

Using git bisect I traced the origin of the bug to this commit:

https://git.musl-libc.org/cgit/musl/commit/?id=54ca677983d47529bab8752315ac1a2b49888870

which is the commit that is described as "implement priority inheritance
mutexes".

From my analysis it appears that _m_waiters is used by the
priority inheritance logic to maintain some state (as described in the
commit message) but that conflicts with some use of _m_waiters in the
condition variable implementation.

The consequence is that pthread_mutex_lock erroneously returns EDEADLK.

I don't understand the code well enough to produce a fix.

The demo code (a cut version of some production code) will reproduce the
failure. Commenting out the pthread_mutexattr_setprotocol call in
the iot_mutex_init function at the end of the thread.c file will cause the
code to work as intended (without priority inheritance). The code works
fine either way with the GNU lib.

BTW can I recommend that the "magic numbers"  used to represent mutex modes
be replaced at some point with defined constants as it would make the code
much easier to follow.

This is my first post to this list so I hope this message is on the right
list and is helpful.

Edward Scott

[-- Attachment #2: Type: text/html, Size: 1959 bytes --]

             reply	other threads:[~2020-09-24 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-24 14:58 Edward Scott [this message]
2020-09-24 16:14 ` Rich Felker
2020-10-26 19:49   ` Rich Felker

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='CANGYPwMccU6RFsSVvjnxQJCjG1_=oEYOVdYg5GwMrShr=oy7fw@mail.gmail.com' \
    --to=ed@iotechsys.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).