[FFmpeg-devel] [PATCH] Fix threaded mpeg*video encoding

Michael Niedermayer michaelni
Thu Jul 1 11:50:50 CEST 2010


On Thu, Jul 01, 2010 at 04:01:24AM +0100, M?ns Rullg?rd wrote:
> Michael Niedermayer <michaelni at gmx.at> writes:
> 
> > On Wed, Jun 30, 2010 at 03:49:34PM +0100, Mans Rullgard wrote:
> >> This allocates per-thread copies of some buffers which are updated
> >> concurrently from the encoding threads.
> >
> > almost all buffers are updated concurrently from the threads
> 
> If several threads are using the same memory locations concurrently,
> there is a problem.

threads read and write into te same locations, this doesnt implicate that
they use the read values.

for example see:
    a = dc_val[ - 1];
    b = dc_val[ - 1 - wrap];
    c = dc_val[ - wrap];

    /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */
    if(s->first_slice_line && n!=3){
        if(n!=2) b=c= 1024;

first_slice_line is 1 and n is 0 or 1 if the b/c values are from a different
thread.
This also makes logic sense as we cant predict accross slices


> 
> > some of what you change doesnt look like its even used by encoders
> > though
> >
> > is this fixing a bug?
> > if so please elaborate what and where. My guess would be toward
> > ac_val being the one causing the issues.
> 
> The threaded regression tests are failing randomly with pthreads enabled:
> 
> http://fate.multimedia.cx/index.php?test_result=66882641
> http://fate.multimedia.cx/index.php?test_result=66852547
> http://fate.multimedia.cx/index.php?test_result=66876769
> 
> Those are just a few examples.  Valgrind complained about most of
> those buffers, particularly ac_val and dc_val, and I add a couple
> since they were written close to the places valgrind identified.  Race
> detection is never exact.

could you try to just change ac_val and see if this makes the issue
go away?
for ac_val i found ff_mpeg4_clean_buffers() as possible reason for the
race, for the others i am not aware of code that can lead to a race

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100701/30d671b1/attachment.pgp>



More information about the ffmpeg-devel mailing list