ccurllibcurlgnutls

Is libcurl thread safe when built with GnuTLS


One of the requirement for libcurl to be thread safe is that the underlying SSL library should be thread safe.

According to documentation of GnuTLS, it is thread safe by design.

The GnuTLS library is thread safe by design, meaning that objects of the library such as TLS sessions, can be safely divided across threads as long as a single thread accesses a single object. This is sufficient to support a server which handles several sessions per thread. Read-only access to objects, for example the credentials holding structures, is also thread-safe.

However there are few use cases that needs to be taken care.

A gnutls_session_t object could also be shared by two threads, one sending, the other receiving. However, care must be taken on the following use cases:

Does libcurl take care of above use cases?


Solution

  • Yes it does.

    libcurl does not use gnutls_session_t objects from multiple threads, so those mentioned precautions don't apply (nor does it do any of the other things said to not be thread-safe). Threaded libcurl use with GnuTLS (or other TLS backends) should be fine as long as you follow libcurl's thread-safety guidelines.