curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Using libcurl in another library, when/if to call curl_global_init?

From: Mark Wielaard via curl-library <curl-library_at_lists.haxx.se>
Date: Sat, 23 Apr 2022 00:14:36 +0200

Hi,

On Thu, Mar 31, 2022 at 03:19:51PM +0200, Mark Wielaard via curl-library wrote:
> 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?

Since it does seem we were interpreting the documentation a bit too
strictly I did propose a patch for elfutils that does lazy
initialization using pthread_once.

https://sourceware.org/pipermail/elfutils-devel/2022q2/004934.html

This makes sure we don't race against ourselves. And for programs
using our library we can assume they will call curl_global_init before
creating a multi-threaded environment and calling our own handle
initialization functions.

It would still be great if curl_global_init itself could be made
thread-safe to call.

Thanks,

Mark
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-04-23