cURL / Mailing Lists / curl-library / Single Mail

curl-library

Reusing easy handle from multiple threads

From: Vladimir Grishchenko <vladgri_at_hotmail.com>
Date: Mon, 18 Apr 2011 18:53:02 -0700

I'd like to maintain a pool of reusable easy handles. The reason being is that I don't want to destroy a handle after each transfer as that (as
 far as I understand) will make it impossible to benefit from
the connection cache that is maintained per handle. There will be multiple threads performing transfers, so each handle in the pool can get assigned to a new thread each time it is used. Certainly a protocol will be in place by which each thread must acquire a handle in a thread-safe manner before using it, so handle usages will be serialized something like the following:

T1 acquires H1 from the pool
T1 calls curl_easy_setopt(H1)
T1 calls curl_easy_perform(H1)
T1 returns H1 to the pool
T2 acquires H1 from the pool

T2 calls curl_easy_setopt(H1)

T2 calls curl_easy_perform(H1)

T2 returns H1 to the pool

....

Is this safe? I'm aware that multi-handle is another way of doing things - this question is specific to the easy interface.

Thanks!

-Vladimir
                                               
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-19