cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Thread safety and ConnectionStore

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 3 Jun 2014 11:09:49 +0200 (CEST)

On Mon, 2 Jun 2014, Lindley French wrote:

Hi!

Thanks for your mail and interest in libcurl. Do note that we use the
curl-library mailing list for libcurl stuff and development, curl-users is
primarily for users of the curl command line tool!

> I am using curl in a multi-threaded context. According to the documentation,
> curl is supposed to be completely thread-safe. However, ThreadSanitizer
> warns me about the connection_id_counter variable in the ConnectionStore()
> method; and indeed, local statics and threads don't go well together.

I would say that's a mistake. The connection id is used for logging/output but
we should still make sure it is handled correctly. That number should be kept
in the connection cache instead of static.

> I can fix it and make a pull request on github. My question is, what is the
> preferred thread safety mechanism with curl? A quick search doesn't turn up
> much in the way of mutexes or atomics in the current code. Any suggestions?

There's no need for mutexes or similar for that. Thread-safety in libcurl
means you can use all functions from any number of threads, but you cannot use
the same handle in more than one thread at a time.

But please: take follow-ups to this subject to the curl-library list where I'm
also CC'ing this response!

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-06-03