cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: living _with_ global variables

From: Jamie Lokier <jamie_at_shareable.org>
Date: Wed, 28 Dec 2005 05:56:35 +0000

Bryan Henderson wrote:
> But thread-safe isn't essential for these routines, because they can be
> called at the very beginning and end of a program, when it is only one
> thread. The code at that level doesn't necessarily know that this library
> will be used and thus needs to be initialized, but that requirement can
> propagate up through each layer's own global_init() function.

By the way, if the functions are called with the address of a "lock"
function, an "unlock" function, and a "lock" - all as arguments - then
they are thread-safe too without any dependence on a particular thread
implementation. That's provided the caller always passes the same
values for those arguments.

Then again, if the caller is thread-aware it can simply arrange to
call the function once anyway, using whatever mechanism the thread
implementation has for calling a function once.

-- Jamie
Received on 2005-12-28