On Thu, May 15, 2008 at 1:32 PM, Behdad Esfahbod &lt;<a href="mailto:behdad@behdad.org">behdad@behdad.org</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I know I thought of a problem before... Here it is. &nbsp;In your loop:<br>
<div class="Ih2E3d"><br>
+ &nbsp; &nbsp;while (solid_surface_cache.size) {<br>
+ &nbsp; &nbsp; &nbsp; cairo_surface_t *surface = solid_surface_cache.cache[solid_surface_cache.size-1].surface;<br>
+ &nbsp; &nbsp; &nbsp; solid_surface_cache.size--;<br>
+<br>
+ &nbsp; &nbsp; &nbsp; /* release the lock to avoid the possibility of a recursive<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;* deadlock when the scaled font destroy closure gets called */<br>
+ &nbsp; &nbsp; &nbsp; CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_surface_cache_lock);<br>
+ &nbsp; &nbsp; &nbsp; cairo_surface_destroy (surface);<br>
+ &nbsp; &nbsp; &nbsp; CAIRO_MUTEX_LOCK (_cairo_pattern_solid_surface_cache_lock);<br>
+ &nbsp; &nbsp;}<br>
<br>
</div>solid_surface_cache.size is not declared volatile, so compiler is free<br>
to replace that with a simple countdown loop, but since it may be<br>
modified from other threads, you may end up destroying an entry twice.<br>
Or things like that.<br>
<div><div></div><div class="Wj3C7c"></div></div></blockquote><div><br>Surely the calls to unlock and lock prevent that optimization? Data that&#39;s protected by explicit synchronization shouldn&#39;t need to be declared volatile.<br>
</div></div><br clear="all">Rob<br>-- <br>&quot;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.&quot; [Isaiah 53:5-6]