cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: multi-threaded application using libcurl, about synchronized access

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 4 Feb 2010 14:36:24 +0100 (CET)

On Wed, 3 Feb 2010, Selçuk Cihan wrote:

> "The first basic rule is that you must never share a libcurl handle (be it
> easy or multi or whatever) between multiple threads. Only use one handle in
> one thread at a time."
>
> I would like to know if this basic rule applies to synchronized access?

It's the rule for all libcurl calls basically.

> Calls to curl api are guarded by mutexes, is this enough? In callback
> functions i do not use mutexes, i just lock the mutex before calling
> curl_multi_perform, hopefully callbacks are also protected by the mutex.

Since the callbacks are then done within the mutex guards, that will be fine.

> I implemented the above mutex guarded multi-threaded application, and i am
> getting segfaults from libcurl calls randomly, that is why i would like to
> know if i am doing the wrong thing by calling curl from different threads.

Are you perhaps using SSL based URLs (HTTPS or FTPS) and if so do you use the
SSL libary's mutex functionality?

-- 
  / daniel.haxx.se

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