Cairo exports and more (was Re: [cairo] Re: Munging header files
for export (and other) attributes)
Bill Spitzak
spitzak at d2.com
Fri Sep 16 15:02:17 PDT 2005
mental at rydia.net wrote:
> Quoting Bill Spitzak <spitzak at d2.com>:
>
>
>>_cairo_backend_foo() {
>> static char been_here = false;
>> if (!been_here) {
>> lock(backend_internal_mutex);
>> if (!been_here) {
>> initialize_stuff();
>> been_here = true;
>> }
>> unlock(backend_internal_mutex);
>> }
>>}
>
>
> I got my knuckles rapped for doing that kind of thing once.
>
> Turns out, that outer test of !been_here isn't safe on
> multi-processor systems: without the memory barrier presumably
> introduced by lock(), you can't assume that the value of been_here
> will reflect the value visible to the other CPU(s) due to cache
> issues, or that the compiler won't play nasty tricks on you.
>
> Now, especially if you make been_here volatile, you can _get away
> with it_ on some compilers and platforms. But it's not portable or
> guaranteed.
>
> Basically you must only test been_here within the protection of the
> lock.
It's true that it should be marked violatile, but I think you missed the
fact that I re-tested the variable inside the lock.
More information about the cairo
mailing list