mailing list of musl libc
 help / color / mirror / code / Atom feed
From: zuotina  <zuotingyang@126.com>
To: musl@lists.openwall.com
Subject: [musl] Re:Re: [musl] [pthread] pthread_barrier_wait  invalid case
Date: Fri, 17 Dec 2021 22:28:14 +0800 (CST)	[thread overview]
Message-ID: <14675e48.759d.17dc8cb1e6c.Coremail.zuotingyang@126.com> (raw)
In-Reply-To: <20211216181600.GN7074@brightrain.aerifal.cx>

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

At 2021-12-17 02:16:07, "Rich Felker" <dalias@libc.org> wrote:

>On Thu, Dec 16, 2021 at 11:25:35PM +0800, zuotina wrote:
>> Hi everrone
>> 
>> 
>> I encountered a panic problem when using timer_create recently.
>> Although the probability is small, it still happened.
>> Finaly I found there is a problem in the code of phtread_barrier_wait, 
>> and review code found that there may be problems in the following place, 
>> 81  a_store(&b->_b_lock, 0);
>> 82  if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
>> If scheduling occurs between lines 81 and 82, it will be not good.
>> So I did an experiment and modified the source code of pthread_barrier_wait to verify my guess
>> ```c
>> 81  a_store(&b->_b_lock, 0);
>>                  /* If it is scheduled out here, when another thread executes pthread_barrier_wait again, 
>>                     it can go through the entire function happily, that is, it will not be blocked */
>>       syscall(yiled); // new add for test
>>                // When the dispatch comes back, this b has been released
>> 82  if (b->_b_waiters) __wake(&b->_b_lock, 1, 1);
>> ```
>
>The intent here is that it's not possible that b has been released,
>because all waiters have to synchronize on b->_b_inst. It's possible
>there's a bug here. I'll look. What arch are you running on?

 running on aarch64. 
 Looking forward to fix, thank you
>> Here is an example of timer_create (src/time/timer_create.c)
>> There are two threads A and B call pthread_barrier_wait. 
>> The call is as follows
>> A thread: (timer_create // parent thread)
>> {
>>        .....
>>       // new add for test---begin
>>        while(b->_b_inst == NULL) {
>>                 syscall(yield);
>>        }
>>      // new add for test---end
>>      pthread_barrier_wait();
>> }
>> B thread: (start // child thread)
>> {
>>        .....
>>       //  Ensure that this function is advanced to the if (!inst) {} branch of barrier_wait
>>       pthread_barrier_wait();
>> }
>> 
>> 
>> In short, the reason for panic is that pthread_barrier_wait is not blocked as expected;
>> I hope you help to confirm whether there is a problem with the implementation 
>> of pthread_barrier_wait or am I wrong?
>> 
>> 
>> Looking forward to your reply. Thank you. 
>
>Thanks for the report.
>
>Rich

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

  reply	other threads:[~2021-12-17 14:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 15:25 zuotina
2021-12-16 18:16 ` Rich Felker
2021-12-17 14:28   ` zuotina [this message]
2022-01-19 14:56     ` [musl] Re:[musl] " zuotina
2022-01-20  2:19       ` 答复: " zhaohang (F)

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=14675e48.759d.17dc8cb1e6c.Coremail.zuotingyang@126.com \
    --to=zuotingyang@126.com \
    --cc=musl@lists.openwall.com \
    --subject='[musl] Re:Re: [musl] [pthread] pthread_barrier_wait  invalid case' \
    /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

Code repositories for project(s) associated with this 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).