From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Vitaly Buka <vitalybuka@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 13:41:58 -0700 [thread overview]
Message-ID: <CALoOobMHSEJfRgYiz4WTMw1SWCvXaEgvLN5rHHBUF42FC6j1qA@mail.gmail.com> (raw)
In-Reply-To: <20200920120957.852821-1-vitalybuka@google.com>
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()?
> + /* 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
next prev parent reply other threads:[~2020-09-20 20:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-20 9:57 Vitaly Buka
2020-09-20 12:09 ` Vitaly Buka
2020-09-20 20:41 ` Paul Pluzhnikov [this message]
2020-09-20 21:26 ` Vitaly Buka
2020-09-20 23:36 ` Vitaly Buka
2020-09-20 23:37 ` Vitaly Buka
2020-09-21 8:31 ` Vitaly Buka
2020-09-30 16:01 ` Joseph Myers
2021-04-17 16:16 ` Vitaly Buka
2021-04-17 17:11 ` Vitaly Buka
2021-04-17 17:13 ` Vitaly Buka
2021-04-17 17:22 ` Vitaly Buka
2021-04-17 18:01 ` Paul Pluzhnikov
2021-04-20 22:51 ` Vitaly Buka
2021-04-20 23:40 ` Paul Pluzhnikov
2021-04-26 19:20 ` Vitaly Buka
2021-04-26 19:23 ` Vitaly Buka
2021-04-26 19:27 ` Vitaly Buka
2021-05-13 13:15 ` Adhemerval Zanella
2021-05-14 6:50 ` Vitaly Buka
2021-04-17 17:36 ` Paul Pluzhnikov
2021-04-17 20:19 ` Florian Weimer
2021-04-19 2:48 ` Vitaly Buka
2021-04-19 2:57 ` Vitaly Buka
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=CALoOobMHSEJfRgYiz4WTMw1SWCvXaEgvLN5rHHBUF42FC6j1qA@mail.gmail.com \
--to=ppluzhnikov@google.com \
--cc=libc-alpha@sourceware.org \
--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).