cURL / Mailing Lists / curl-library / Single Mail


curl_multi_perform problem in multi threaded aplication

From: Milan KÝŠpek <>
Date: Thu, 03 May 2007 12:45:39 +0200 (CEST)

Sorry for starting new thread, but I thing it will be better than continue in the old one.

Description of problem.

I have multithreaded aplication. In component HttpClient, I must be able to send requests to numerous servers (about 10). And to each server can be sent more requests. So I need to use curl_multi_handle.

If I get new request to server from some thread, I lookup in my storage map, if there is any multi_handle that serves connection to this server. If not, I create new easy_handle, new multi_handle and add it to my storage map, add easy_handle to multi, start new thread and in it I call curl_multi_perform. If the multi_handle exists I only add new easy_handle to existing multi_handle.

Well and it does not work. Is It because I create the handles in one thread and perform it in another? Or is there any other mistake?

I use this optin when I create easy handle:

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt (curl, CURLOPT_NOBODY, 1); - I send all relevant information in headers

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - this I call only in debug version

Is there any way to init curl_handles in one thread and use it in another? Or I can use it only in thread where it was created?
And what happend if I create easy_handle in one thread and add it to the multi_handle in other thread? Will it crash too?
Thanks for advice or your experiences
Received on 2007-05-03