cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Is the callback specified in CURLOPT_WRITEFUNCTION thread-safe?

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Tue, 1 Jul 2014 21:41:42 +0200

On Tue, Jul 01, 2014 at 09:14:24PM +0530, Ajay Garg wrote:
> Is it safe to pass the same callback-function as the parameter to
> CURLOPT_WRITEFUNCTION in different threads?
> Note that the threads may be highly concurrent, sending and receiving requests/
> responses simultaneously.
>
> Or we run the risk of mixing up received-data (in different threads)?

This is entirely up to the callback function. libcurl is thread safe when used
in the recommended way. One of those stipulations is that a libcurl handle must
not be shared between threads. If that's followed there will never be an
opportunity to mix up received data since the handle passed in to the callback
in each thread will be different.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-07-01