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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3DC1D3857814 for ; Fri, 18 Jun 2021 05:45:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3DC1D3857814 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-5-i_w3uo39PA-x8l_y8jCKWA-1; Fri, 18 Jun 2021 01:45:54 -0400 X-MC-Unique: i_w3uo39PA-x8l_y8jCKWA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 519331926DC0; Fri, 18 Jun 2021 05:45:53 +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 78DBA6062C; Fri, 18 Jun 2021 05:45:52 +0000 (UTC) From: Florian Weimer To: Siddhesh Poyarekar Cc: Siddhesh Poyarekar via Libc-alpha Subject: Re: [PATCH] malloc: Ensure that ptmalloc_init runs only once References: <20210617103217.2633690-1-siddhesh@sourceware.org> <87a6no4l71.fsf@oldenburg.str.redhat.com> <68f4386f-9ae5-8791-31bf-7dcf14479847@sourceware.org> Date: Fri, 18 Jun 2021 07:45:50 +0200 In-Reply-To: <68f4386f-9ae5-8791-31bf-7dcf14479847@sourceware.org> (Siddhesh Poyarekar's message of "Fri, 18 Jun 2021 08:01:30 +0530") Message-ID: <87y2b7u3n5.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.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.2 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: Fri, 18 Jun 2021 05:45:57 -0000 * Siddhesh Poyarekar: > On 6/17/21 8:01 PM, Florian Weimer via Libc-alpha wrote: >> * 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. > > Yes but I wonder if we should rely on that. If we decide to rely on > this semantic then we implicitly specify thread creation through > methods other than pthread_create that happen to not call malloc as > unsupported. There is no way to allocate a TCB for such foreign threads, and malloc depends on the TCB, so this is not something that can work for completely different reasons. THanks, Florian