public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: honan li <sayibobo@gmail.com>
To: libc-help@sourceware.org
Subject: Could you kindly explain this modification about pthread_cond_destroy?
Date: Mon, 27 Nov 2017 07:53:00 -0000	[thread overview]
Message-ID: <CA+xL5a-X4U0Ob-gUkfo87ox9kY85W8c-QKVXd7H12r0hP5SMVg@mail.gmail.com> (raw)

We came across a Linux app issue that while invoke
pthread_cond_destroy, it is pending there forever. After investigation
we find that is because a waiter is being blocked (by
pthread_cond_wait) while doing pthread_cond_destroy.

This issue didn't occur on our previous platform using
glibc2.20(Yocto1.7), while it always occurs after we upgraded to
Yocto2.2(includs glibc after version 2.24). We checked glibc history
and find issue seems related to commit ed19993b5 by Torvald Riegel on
31 Dec 2016.

We do noticed the comment of __pthread_cond_destroy, it mentioned "A
correct program must make sure that no waiters are blocked on the
condvar when it is destroyed.", "It must also ensure that no signal or
broadcast are still pending to unblock waiters." and "destruction that
is concurrent with still-active waiters is probably neither common nor
performance critical.".
But back to our issue, on the Qualcomm platform we are working on,
there are many places invoking pthread_cond_destroy, but after each
pthread_cond_destroy, thread or even the process would exit, and at
least for now it seems working all right on glibc2.20. Could you
kindly explain what is the potential risk of the case?

//below is the simple app to verify the issue. App always got stuck on
pthread_cond_destroy on glibc2.25, while on glibc2.20 it ends well.
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void *thread1(void *);
void *thread2(void *);
int main(void)
{
     pthread_t t_a;
     pthread_t t_b;
     pthread_create(&t_a,NULL,thread1,(void *)NULL);
     pthread_create(&t_b,NULL,thread2,(void *)NULL);
     sleep(1);

     pthread_cond_destroy(&cond);
     pthread_mutex_destroy(&mutex);
     exit(0);
}
void *thread1(void *args)
{
    pthread_cond_wait(&cond,&mutex);
}
void *thread2(void *args)
{
}

             reply	other threads:[~2017-11-27  7:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27  7:53 honan li [this message]
2017-11-27 12:03 ` Florian Weimer
2017-11-27 12:15   ` Adhemerval Zanella

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=CA+xL5a-X4U0Ob-gUkfo87ox9kY85W8c-QKVXd7H12r0hP5SMVg@mail.gmail.com \
    --to=sayibobo@gmail.com \
    --cc=libc-help@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).