cURL / Mailing Lists / curl-library / Single Mail


Re: curl_global_init

From: McGarvey, Kevin <>
Date: Thu, 14 Feb 2008 18:23:45 -0500

> ------------------------------
> Message: 9
> Date: Thu, 14 Feb 2008 22:04:05 +0100 (CET)
> From: Daniel Stenberg <>
> Subject: Re: curl_global_init
> To: libcurl development <>
> Message-ID: <>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> On Thu, 14 Feb 2008, Georg Lippitsch wrote:
> > Because if it is true, it would make it impossible to use
> curl in libraries
> > that are dynamically loaded by other programs (like
> plug-ins), because you
> > can never be sure that no threads are running.
> If you use libcurl in a plugin that is run in an invidiual
> thread and your
> plugin calls curl_global_init() and there might be more than
> one plugin like
> this running within the same program, then correct you cannot
> safely use this
> approach.
> But the problem is not really running it in multiple threads,
> the problem is
> when you run the inits simultaneously in multiple threads so
> for your plugin
> example you can make some mutex magic that prevents the race
> to happen.
> --
Based on what you wrote, the documentation is incorrect. It says the

"You must not call it when any other thread in the program (i.e. a
thread sharing the same memory) is running. This doesn't just mean no
other thread that is using libcurl. Because curl_global_init() calls
functions of other libraries that are similarly thread unsafe, it could
conflict with any other thread that uses these other libraries."

But what you are saying here is that the issue is confined to multiple
threads running curl_global_init.

The scenario that Georg described is exactly what we are doing. We have
a C++ library that is plugged in to a Java Virtual Machine via JNI. We
can use a mutex to single-thread calls to curl_global_init, but we are
not the first thread running and there will be many threads running that
are not ours when we call curl_global_init.

Are we OK as long as two threads don't call curl_global init

Received on 2008-02-15