From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 08E2D385843E for ; Thu, 31 Mar 2022 13:19:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08E2D385843E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x11.wildebeest.org [172.31.17.147]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 0B7AA304319C; Thu, 31 Mar 2022 15:19:51 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id 7537B2E8105D; Thu, 31 Mar 2022 15:19:51 +0200 (CEST) Date: Thu, 31 Mar 2022 15:19:51 +0200 From: Mark Wielaard To: libcurl development Cc: Catalin Raceanu , elfutils-devel@sourceware.org Subject: Re: Using libcurl in another library, when/if to call curl_global_init? Message-ID: References: <1ea188affb14c7b55ec1d54fe95627d83e730bb4.camel@klomp.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2022 13:19:55 -0000 Hi, On Thu, Mar 31, 2022 at 04:00:16PM +0300, Catalin Raceanu via curl-library wrote: > On 31-Mar-22 15:04, Mark Wielaard wrote: > > whether there is a thread-safe way to call > > curl_global_init at a later time (to get rid of the library constructor > > init function). > > I believe that this is an exact fit for C==11's std::call_once(). Boost also > has an equivalent, that most likely predates the other, in case older c++ > standard is used. Thanks. Our library is pure C, but we can probably rely on pthread_once if it is allowable to call curl_global_init at a later time when multiple threads are already running. The reason we aren't doing that now is because the curl_global_init documentation explicitly states "You must not call it when any other thread in the program is running". But maybe we are interpreting the documentation too strictly? Are there examples of other libraries using libcurl which do this global initialization lazily from which we can steal some code? Thanks, Mark