From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C969E3857431 for ; Thu, 17 Jun 2021 14:31:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C969E3857431 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-Uq4h1PfdN8KGXZ6ZTCQImw-1; Thu, 17 Jun 2021 10:31:17 -0400 X-MC-Unique: Uq4h1PfdN8KGXZ6ZTCQImw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78300100CECA; Thu, 17 Jun 2021 14:31:16 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACFBE100164C; Thu, 17 Jun 2021 14:31:15 +0000 (UTC) From: Florian Weimer To: Siddhesh Poyarekar via Libc-alpha Cc: Siddhesh Poyarekar Subject: Re: [PATCH] malloc: Ensure that ptmalloc_init runs only once References: <20210617103217.2633690-1-siddhesh@sourceware.org> Date: Thu, 17 Jun 2021 16:31:14 +0200 In-Reply-To: <20210617103217.2633690-1-siddhesh@sourceware.org> (Siddhesh Poyarekar via Libc-alpha's message of "Thu, 17 Jun 2021 16:02:17 +0530") Message-ID: <87a6no4l71.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: Thu, 17 Jun 2021 14:31:21 -0000 * Siddhesh Poyarekar via Libc-alpha: > It is possible that multiple threads simultaneously enter > ptmalloc_init and succeed the < 0 check. Make the comparison and > setting of __malloc_initialized atomic so that only one of them goes > through. Additionally, if a thread sees that another thread is > running the initialization (i.e. __malloc_initialized == 0) then wait > till it is done. No, this cannot happen because pthread_create calls malloc before creating the new thread. Thanks, Florian