[cairo] [PATCH] Do not hold mutexes when calling destructors.

Robert O'Callahan robert at ocallahan.org
Fri May 16 01:05:12 PDT 2008

On Thu, May 15, 2008 at 1:32 PM, Behdad Esfahbod <behdad at behdad.org> wrote:

> I know I thought of a problem before... Here it is.  In your loop:
> +    while (solid_surface_cache.size) {
> +       cairo_surface_t *surface =
> solid_surface_cache.cache[solid_surface_cache.size-1].surface;
> +       solid_surface_cache.size--;
> +
> +       /* release the lock to avoid the possibility of a recursive
> +        * deadlock when the scaled font destroy closure gets called */
> +       CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_surface_cache_lock);
> +       cairo_surface_destroy (surface);
> +       CAIRO_MUTEX_LOCK (_cairo_pattern_solid_surface_cache_lock);
> +    }
> solid_surface_cache.size is not declared volatile, so compiler is free
> to replace that with a simple countdown loop, but since it may be
> modified from other threads, you may end up destroying an entry twice.
> Or things like that.

Surely the calls to unlock and lock prevent that optimization? Data that's
protected by explicit synchronization shouldn't need to be declared

"He was pierced for our transgressions, he was crushed for our iniquities;
the punishment that brought us peace was upon him, and by his wounds we are
healed. We all, like sheep, have gone astray, each of us has turned to his
own way; and the LORD has laid on him the iniquity of us all." [Isaiah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080516/34c94c01/attachment.htm 

More information about the cairo mailing list