public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: abush wang <abushwangs@gmail.com>,
	triegel@redhat.com,
	abushwang via Libc-alpha <libc-alpha@sourceware.org>,
	adhemerval.zanella@linaro.org
Subject: Re: pthread_rwlock_rdlock return in low priority
Date: Wed, 08 Mar 2023 01:09:23 +0800	[thread overview]
Message-ID: <9189dfbb27c425d89cf490008699dc3a5d3f39e0.camel@xry111.site> (raw)
In-Reply-To: <CAMLoAPab2zP4=t2V10f=E5KNNLqY4ZjjrPtH8-hUj64LvbU4-g@mail.gmail.com>

On Tue, 2023-03-07 at 20:23 +0800, abush wang via Libc-alpha wrote:
> hi, Riegel
> 
> I have noticed reader will return directly on fast-path in
> pthread_rwlock_common.c
> 
> > *  /* We have registered as a reader, so if we are in a read phase, we have
> *>*     acquired a read lock.  This is also the reader--reader fast-path.
> *>*     Even if there is a primary writer, we just return.  If writers are to
> *>*     be preferred and we are the only active reader, we could try to enter a
> *>*     write phase to let the writer proceed.  This would be okay because we
> *>*     cannot have acquired the lock previously as a reader (which could result
> *>*     in deadlock if we would wait for the primary writer to run).  However,
> *>*     this seems to be a corner case and handling it specially not
> be worth the
> *>*     complexity.  */
> *>*  if (__glibc_likely ((r & PTHREAD_RWLOCK_WRPHASE) == 0))
> *>*    return 0;
> *
> However, there is a situation:
>     main, thread_wr, thread_rd.
> 
>     SCHED_FIFO priority:
>         main > thread_wr > thread_rd
>     main first acquires read lock, then create thread_wr which will
> block on the lock.
>     Next, main creates thread_rd. this thread will acquires read lock
> on fast-path even
>     though it has a lower priority compared to thread_wr.
> 
> You can get demo from the following
> repository:https://github.com/emscripten-core/posixtestsuite.git
> ./conformance/interfaces/pthread_rwlock_rdlock/2-1.c
> 
> According to "man -M man-pages-posix-2017/ 3p pthread_rwlock_rdlock"
> 
> > * DESCRIPTION
> *>* The pthread_rwlock_rdlock() function shall apply a read lock to the
> *>* read-write lock referenced by rwlock.  The calling thread acquires the
> *>* read lock  if  a writer does not hold the lock and there are no
> *>* writers blocked on the lock.
> *>>* If  the  Thread  Execution  Scheduling  option  is supported,  and the
> *>* threads involved in the lock are executing with the scheduling
> *>* policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire
> *>* the lock if a writer holds the lock or if writers of higher or equal
> *>* priority are blocked on the lock;  other‐ wise, the calling thread
> *>* shall acquire the lock.
> *
> I was wondering that whether this
> 
> , and whether
> this posix standard should be enforced.

Already declared as WONTFIX several years ago:
https://sourceware.org/bugzilla/show_bug.cgi?id=13701.

And a more general ticket about "POSIX violations in corner cases":
https://sourceware.org/bugzilla/show_bug.cgi?id=25619.



-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

      reply	other threads:[~2023-03-07 17:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 12:23 abush wang
2023-03-07 17:09 ` Xi Ruoyao [this message]

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=9189dfbb27c425d89cf490008699dc3a5d3f39e0.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=abushwangs@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=triegel@redhat.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.
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).