curl-library
Is curl_multi interface thread-safe?
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()
{
while(mThreadAlive)
{
/*
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)) ==
CURLM_CALL_MULTI_PERFORM);
} 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);
curl_easy_cleanup(lEasyHandle);
}
}
}
curl_multi_cleanup(mpMultiHandle);
curl_global_cleanup();
}
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?
Thanks,
Walter
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-10-13