cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl, ActiveX and thread safety

From: Ranger Harke <rharke846_at_gmail.com>
Date: Wed, 19 Dec 2007 11:12:39 -0500

Hello,

I am working on integrating libcurl into my application, and have run
across some notes in the API which scare me somewhat. Specifically, I
noticed that curl_global_init and curl_global_cleanup are marked as
thread-unsafe, and should never be called "when any other thread is
running".

Ordinarily, this would be fine, except that the application I am
developing is an ActiveX component (or a COM object, or whatever you
prefer to call it... my application is a specialized DLL file,
basically. And yes, this means that I am developing on Win32). As a
result, my program runs in-process with another program and there is
no point in my code where I can guarantee that no other thread is
running. In fact it is pretty much guaranteed that there will never be
such a place.

I have compiled libcurl with HTTP_ONLY (at least for now) and it is
statically-linked into my DLL.

I did a bit of poking about in the libcurl source, and it looks to me
that, in my setup, the only thing that curl_global_init sets up is the
Winsock. It *feels* like it should be safe to call this from the base
thread of my ActiveX component (that is to say, before *I* spawn any
new threads) but I must admit that I know very little about thread
safety of Winsock initialization.

Can anyone offer any deeper insight into the specific aspects of
global_init and global_cleanup that are not thread safe and therefore
might trip me up given this situation? I admit that I have not gotten
a chance yet to "just try it" as I ran into the scary part of the
documentation before I wrote much code. I am going to continue forward
and see what I run into, but I wanted to put this question out there
to see if there were any known pitfalls before I got too far.

Thanks very much for any insight,
...Ranger Harke
Received on 2007-12-19