unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Vitaly Buka via Libc-alpha <libc-alpha@sourceware.org>
To: Paul Pluzhnikov <ppluzhnikov@google.com>
Cc: GLIBC Devel <libc-alpha@sourceware.org>
Subject: Re: [PATCH] stdlib: Fix data race in __run_exit_handlers
Date: Sun, 20 Sep 2020 16:36:32 -0700	[thread overview]
Message-ID: <CAPjTjwudpZ2bC-pCpqDddPVzH27u_1U1xeUXye1TmvAaskKxtw@mail.gmail.com> (raw)
In-Reply-To: <CAPjTjwvjLdBfU0ZQECaxn__FHdcLx7RK+z-3oBA1XZq8Q2GZcw@mail.gmail.com>

Oh, this atomics are not what I thought. So the test reproduced bugs in the
test.
I tried different approaches and I failed to reproduce the data race.

On Sun, 20 Sep 2020 at 14:26, Vitaly Buka <vitalybuka@google.com> wrote:

>
>
> On Sun, 20 Sep 2020 at 13:42, Paul Pluzhnikov <ppluzhnikov@google.com>
> wrote:
>
>> On Sun, Sep 20, 2020 at 5:10 AM Vitaly Buka via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
>>
>> > +static void *
>> > +threadfunc (void *unused)
>> > +{
>> > +  for (; done < 1e6;)
>> > +    {
>> > +      if (added < done + 100)
>> > +        {
>> > +          __cxa_atexit (&atexitcb, (void *)(++added), __dso_handle);
>>
>> Isn't there a data race on "added" here (in addition to a data race on
>> "done")?
>> What prevents two threads from observing "added == 100" at the same
>> time and adding two calls with value of 101, which would later trigger
>> abort() in exitcb()?
>>
>
> They are atomic. Isn't (++added) guarantee to return different values in
> all threads?
>
>
>>
>> > +  /* With default 8MiB Linux stack size, creating 1024 threads can
>> cause
>> > +     VM exhausiton on 32-bit machines.  Reduce stack size of each
>> thread to
>> > +     128KiB for a maximum required VM size of 128MiB.  */
>>
>> This comment is far removed from the computation of kStacksize (and
>> the name violates the naming conventions used here).
>>
>> I suggest:
>>
>>   size_t stack_size = 128 << 10; /* 128KiB  */
>>   if (stack_size < PTHREAD_STACK_MIN) stack_size = PTHREAD_STACK_MIN;
>>
>> Also, I suspect that 32KiB would be more than enough for stack size here.
>>
>> > +  for (i = 0; i < kNumThreads; ++i)
>>
>> Since kNumThreads isn't used anywhere else, I suggest making it a local:
>>
>>   const int num_threads = 50;
>>
>> --
>> Paul Pluzhnikov
>>
>

  reply	other threads:[~2020-09-20 23:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20  9:57 [PATCH] stdlib: Fix data race in __run_exit_handlers Vitaly Buka via Libc-alpha
2020-09-20 12:09 ` Vitaly Buka via Libc-alpha
2020-09-20 20:41   ` Paul Pluzhnikov via Libc-alpha
2020-09-20 21:26     ` Vitaly Buka via Libc-alpha
2020-09-20 23:36       ` Vitaly Buka via Libc-alpha [this message]
2020-09-20 23:37         ` Vitaly Buka via Libc-alpha
2020-09-21  8:31           ` Vitaly Buka via Libc-alpha
2020-09-30 16:01             ` Joseph Myers
2021-04-17 16:16               ` Vitaly Buka via Libc-alpha
2021-04-17 17:11                 ` Vitaly Buka via Libc-alpha
2021-04-17 17:13                   ` Vitaly Buka via Libc-alpha
2021-04-17 17:22                     ` Vitaly Buka via Libc-alpha
2021-04-17 18:01                       ` Paul Pluzhnikov via Libc-alpha
2021-04-20 22:51                         ` Vitaly Buka via Libc-alpha
2021-04-20 23:40                           ` Paul Pluzhnikov via Libc-alpha
2021-04-26 19:20                             ` Vitaly Buka via Libc-alpha
2021-04-26 19:23                               ` Vitaly Buka via Libc-alpha
2021-04-26 19:27                                 ` Vitaly Buka via Libc-alpha
2021-05-13 13:15                                   ` Adhemerval Zanella via Libc-alpha
2021-05-14  6:50                                     ` Vitaly Buka via Libc-alpha
2021-04-17 17:36               ` Paul Pluzhnikov via Libc-alpha
2021-04-17 20:19                 ` Florian Weimer
2021-04-19  2:48                   ` Vitaly Buka via Libc-alpha
2021-04-19  2:57                     ` Vitaly Buka via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPjTjwudpZ2bC-pCpqDddPVzH27u_1U1xeUXye1TmvAaskKxtw@mail.gmail.com \
    --to=libc-alpha@sourceware.org \
    --cc=ppluzhnikov@google.com \
    --cc=vitalybuka@google.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).