curl / Mailing Lists / curl-library / Single Mail


Re: Global lock for lazy PSL loading ?

From: Daniel Stenberg <>
Date: Tue, 13 Dec 2016 14:51:07 +0100 (CET)

On Mon, 12 Dec 2016, Tim Ruehsen wrote:

> I would like to improve the PSL code in Curl_cookie_add(), namely use
> psl_latest() instead of psl_builtin() if possible.
> That function eventually introduces (local) loading of the latest available
> PSL data (either DAFSA or plain text PSL). So I think of a static/global
> psl_ctx_t variable, that will be lazy- initialized on the first call to
> Curl_cookie_add().
> That needs a global locking function... well, what do you suggest ? [I am
> pretty sure that Curl_share_lock() is not the solution (might result in
> several one PSL loading per Curl_easy instance), but didn't find a better
> function yet.]

This is an interesting problem.

libcurl doesn't have a lock function for global context. It was designed to
not have any global context. The only way we _can_ add or init global context
right now is in the curl_global_init() function which is explicitly documented
to not be thread safe - but we need to still be careful since this fact is
often overlooked by users and we don't want to hurt those more than necessary.

The locking functions are in the share APIO because that's the way users can
opt to share data between easy handles.

A common pattern within libcurl is to keep data in the multi handle and share
such data with the participating easy handles, which requires no locking.
That's still not a global context of course.

Then finally: do we really want to add another uncoditional file load (even if
only at first use)? Maybe we want to let users decided that anyway?

List admin:
Received on 2016-12-13