cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Can't call curl_global_init from a thread -- understanding the architecture

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Sat, 4 Oct 2014 23:05:23 +0200

On Sat, Oct 04, 2014 at 04:55:40PM -0400, K. Frank wrote:
> Dan Fandrich commented in the thread:
>
> using libcurl in an enterprise application server
>
> as follows:
>
> As documented, curl_global_init may not be called
> from a thread but from the main function before any
> threads are running.
>
> First, do I understand correctly that if, say, I were to have
> main() in a perfectly ordinary C program spawn a thread
> (say, pthread_create), then it would be illegal for that thread
> to call curl_global_init (even if no other thread in the program
> were to call any curl functions)?

Yes. But sometimes you will be lucky and it will work.

> Second (assuming that the above is correct), what is the
> architectural issue that makes it illegal for any thread but
> the main() thread to call curl_global_init?

See some of the many other threads on this topic, such as
http://curl.haxx.se/mail/lib-2008-02/0116.html or
http://curl.haxx.se/mail/lib-2009-02/0009.html or
http://curl.haxx.se/mail/lib-2010-12/0038.html as a few examples.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-10-04