cURL / Mailing Lists / curl-library / Single Mail


Is curl_multi interface thread-safe?

From: Walter Xiao <>
Date: Thu, 13 Oct 2011 13:47:07 -0400

I have a dedicated thread that keep running to send out HTTP requests via
this function:

void HTTPSenderTask()
some code to put this thread to sleep until waken up by other threads
Int32 lRunningHandles = 0;
do {
while((lCode = curl_multi_perform(mpMultiHandle, &lRunningHandles)) ==
} while (lRunningHandles);

// check completeness of easy handles and clean them up
CURLMsg* lMsg;
Int32 lMsgsLeft = 0;
while ((lMsg = curl_multi_info_read(mpMultiHandle, &lMsgsLeft)))
if (lMsg->msg == CURLMSG_DONE)
CURL* lEasyHandle = lMsg->easy_handle;
curl_multi_remove_handle(mpMultiHandle, lEasyHandle);

So in other threads they will wait up the HTTP sender thread via this code:
curl_multi_add_handle(mpMultiHandle, ipEasyHandle);
WakeUpHTTPSenderThread(); // wake up HTTP Sender thread to start sending
HTTP request in HTTPSenderTask()

My question is, it is highly possible that some threads will
call curl_multi_add_handle() to add easy handle on the mpMultiHandle while
the function HTTPSenderTask is calling curl_multi_perform()
or curl_multi_info_read() or curl_multi_remove_handle(). Are those
curl_multi interface designed as thread-safe, or I have to use my own
locking mechanism to protect my multi-handle?


List admin:
Received on 2011-10-13