[FFmpeg-devel] [PATCH] avcodec thread safety fix

Art Clarke aclarke
Sat May 30 22:24:06 CEST 2009


On Sat, May 30, 2009 at 1:04 PM, Andreas ?man <andreas at lonelycoder.com> wrote:
>> Sorry Andreas, I missed one thing. ?Make sure your static variables
>> are marked "volatile".
>
> Hm, why would that make any difference?

I was conflating Java volatile and C volatile.  Java volatile will
guarantee that reads of a variable always get the latest result across
threads.  C99 volatile will guarantee that lots of C99 experts will
yell back and for at each other about what it does, but eventually
they'll agree it doesn't do memory fencing.

But I based my recommendation on the fact that the
entangled_thread_count was marked volatile in utils.c and that someone
had chosen to do that for a reason.  The ++ operation on that isn't
atomic, but the original developer may have said 'volatile' to try to
at least maximize the odds an error is detected.  In reality (and this
is the mistake that led to the bad recommendation) C99 volatile won't
guarantee that another CPU reading from that location in memory sees
the latest value -- that's a memory fence which is what we don't yet
have.

So I take back my recommendation :)  Ship it.

Another patch from someone else might want to consider removing
volatile on the entangled thread counter, but that's a different
story.

- Art

-- 
http://www.xuggle.com/
xu?ggle (z?' gl) v. To freely encode, decode, and experience audio and video.

Use Xuggle to get the power of FFMPEG in Java.



More information about the ffmpeg-devel mailing list