public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Noah Goldstein <goldstein.w.n@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Noah Goldstein via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: Questions regarding pthread mutex lock/unlock functions in pthread_cond_wait?
Date: Thu, 26 May 2022 19:10:13 -0500	[thread overview]
Message-ID: <CAFUsyfLvkg6iMnubtPZPgBm+pb7RLMgG60e-yxq_Xas_CAaJxg@mail.gmail.com> (raw)
In-Reply-To: <87k0a89skp.fsf@oldenburg.str.redhat.com>

On Thu, May 26, 2022 at 11:17 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Noah Goldstein:
>
> > On Thu, May 26, 2022 at 3:09 AM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * Noah Goldstein via Libc-alpha:
> >>
> >> > 1) Do we need `__pthread_mutex_unlock_usercnt`?
> >>
> >> POSIX says:
> >>
> >> | Attempting to destroy a locked mutex, or a mutex that another thread
> >> | is attempting to lock, or a mutex that is being used in a
> >> | pthread_cond_timedwait() or pthread_cond_wait() call by another
> >> | thread, results in undefined behavior.
> >>
> >> This does not change for PTHREAD_MUTEX_ERRORCHECK mutexes, so I think we
> >> can remove usercnt.
> >
> > Open to a patch removing the `__pthread_mutex_unlock_usercnt`
> > function?
>
> And for making that field unused, yes.

We have a fair number of tests to check that destroy on a "used" lock
returns EBUSY.

User code might have started to rely on it. Maybe best to keep or you
think still go ahead?

>
> >> > 2) Are people in favor of making it so that
> >> > `__pthread_mutex_unlock_usercnt` / `pthread_mutex_cond_lock` go
> >> > through the PLT so that researchers trying to replace `pthread_mutex`
> >> > in applications rely solely on LD_PRELOAD?
> >>
> >> Which functions do you mean exactly?
> >>
> >> I think most internal locks are directly implemented on top of futexes,
> >> so I don't think this would make much of a difference.
> >
> > Can we make it so that
> > `__pthread_mutex_unlock_usercnt` and `__pthread_mutex_cond_lock`
> > used internally by `pthread_cond_{timed}wait`  go through the PLT so
> > that using LD_PRELOAD to entirely replace pthread_mutex in an application
> > is feasible. Think this would be pretty useful to lock researchers / people
> > that want to roll custom locks that are ABI compatible with
> > pthread_mutex/PTHREAD_MUTEX_INITIALIZER.
>
> Why can't they interpose the condition variable implementation as well?
>
> Thanks,
> Florian
>

  parent reply	other threads:[~2022-05-27  0:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 14:10 Noah Goldstein
2022-05-26  8:09 ` Florian Weimer
2022-05-26 15:43   ` Noah Goldstein
2022-05-26 16:17     ` Florian Weimer
2022-05-26 16:28       ` Noah Goldstein
2022-05-26 16:31         ` Florian Weimer
2022-06-02  9:07           ` Yann Droneaud
2022-06-02 14:05           ` Carlos O'Donell
2022-05-27  0:10       ` Noah Goldstein [this message]
2022-05-27  7:36         ` Florian Weimer

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=CAFUsyfLvkg6iMnubtPZPgBm+pb7RLMgG60e-yxq_Xas_CAaJxg@mail.gmail.com \
    --to=goldstein.w.n@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).