[cairo] Re: Linking to Cairo 1.0.2 statically (Win32)

Vladimir Vukicevic vladimirv at gmail.com
Fri Oct 14 14:11:23 PDT 2005


On 10/14/05, Bill Spitzak <spitzak at d2.com> wrote:
> The problem with some kind of library_init() function is that
> programmers will fail to call it, or call it multiple times, or call it
> in parallel threads. It solves nothing. It also means that anybody
> writing any kind of wrapper has to make an init() function, unless they
> themselves solve this very problem so that they can make it call it in a
> thread-safe manner. This should be solved at the lowest level.

If a programmer fails to call it, they will have problems, definitely
no worse problems than if whatever semi-magic is being used fails to
call it (e.g. DllMain).  If they call it multiple times, nothing
should happen, that's why we have static variables for.  If they call
it in parallel threads at the exact same time, well, that's why we
have test-and-set instructions -- though a simple "static int
initialized = 0; if (initialized++) return;" should cover most cases.

If a wrapper has a way to do this type of initialization (e.g. if the
wrapper is in a higher level language that has static constructors,
module initializers, etc.), then there is no need to expose an init
function upwards.  Having the init function exposed allows those
wrappers to make the init decision instead of it happening outside of
their control (if done through magic).

This is really not a new cairo-specific problem; why bother
reinventing the wheel?  Worst case, adding the initialize-once
function call to other calls should be fine as long as we don't put it
in any critical path; surface creation/initialization sounds like the
right place for it, perhaps cairo_t creation.

    - Vlad


More information about the cairo mailing list