From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by sourceware.org (Postfix) with ESMTPS id 18BA53857C61 for ; Sun, 20 Sep 2020 21:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 18BA53857C61 Received: by mail-ej1-x644.google.com with SMTP id q13so14999014ejo.9 for ; Sun, 20 Sep 2020 14:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7pHn3TFFrAh8K5ZWf0rD1/ejlJiOorsAtlRJicnxb88=; b=UGCwELgJLpaVzQrV2nGEoNFVmsE2GS9s2CeaX5yTXvcolLsVTOqrPUGKIayNyHg1qB +ufkU9yDLAUwlqJvPtS9d04JVudhTBmORFXwkVMht8Sjsz5OVh6A8qxYwFpRzHVLNNh5 +jyAfFiOyXdYUhropgxTLeQmz4PqAtVWfTXoEBqoQgmmxwbL9izjOAvLFWO7N4CrCpRA 8L8cYvbzXTYrmIuR1cJmnBda5fGMMkZ6dQXxK76BgEgHqQBDhCAd36v1XNwNF/4Hq8m4 2m3DhH7SQE2wjS1HuyL1z9w7tx9qL4AePALGThDYSCisu9Vyo/sx86IdXRpwzIe6OCzq CezQ== X-Gm-Message-State: AOAM5335qXxmAHzmaPRQujnCJImRHY2EXX9Yu7UPX3m30GuDhcxC2oT+ Z0Ok6o1cmLwcACejq84XTDl4q38DzwR0QAcumAcr5w== X-Google-Smtp-Source: ABdhPJxVDy4X4wpvPwxkPs4Kj8cOQ0sE0yZKGszU7wAqptY6MQWfxX984fDKafJ6qMQ/2/Vd9LAjjWR2TsYohzSTEx8= X-Received: by 2002:a17:906:2c14:: with SMTP id e20mr48752258ejh.205.1600637249863; Sun, 20 Sep 2020 14:27:29 -0700 (PDT) MIME-Version: 1.0 References: <20200920095750.396908-1-vitalybuka@google.com> <20200920120957.852821-1-vitalybuka@google.com> In-Reply-To: From: Vitaly Buka Date: Sun, 20 Sep 2020 14:26:52 -0700 Message-ID: Subject: Re: [PATCH] stdlib: Fix data race in __run_exit_handlers To: Paul Pluzhnikov Cc: GLIBC Devel X-Spam-Status: No, score=-19.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Sep 2020 21:27:32 -0000 On Sun, 20 Sep 2020 at 13:42, Paul Pluzhnikov wrote: > On Sun, Sep 20, 2020 at 5:10 AM Vitaly Buka via Libc-alpha > 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 >