[x264-devel] mb_info_free bug fix for sliced threads

Carotti, Elias eliascrt at amazon.it
Tue Oct 17 08:50:19 UTC 2023


Could someone please check this issue?

Best,
Elias



From: x264-devel <x264-devel-bounces at videolan.org> On Behalf Of Carotti, Elias
Sent: Monday, September 11, 2023 3:56 PM
To: x264-devel at videolan.org
Subject: [x264-devel] mb_info_free bug fix for sliced threads

Hello,
Please find attached a bug fix for a race condition on the mb_info_free callback.

Currently the code looks like the following (encoder/encoder.c):
           x264_threadslice_cond_broadcast( h, 2 );
            /* Do the first row of hpel, now that the previous slice is done */
            if( h->i_thread_idx > 0 )
            {
                x264_threadslice_cond_wait( h->thread[h->i_thread_idx-1], 2 );
                fdec_filter_row( h, h->i_threadslice_start + (1 << SLICE_MBAFF), 2 );
            }
      [....]
      if( h->fdec->mb_info_free && (!h->param.b_sliced_threads || h->i_thread_idx == (h->param.i_threads-1)) )
        {
            h->fdec->mb_info_free( h->fdec->mb_info );
            h->fdec->mb_info = NULL;
            h->fdec->mb_info_free = NULL;
        }
    }

Consider a case with at least three threads:
Thread 0 is lagging behind the other threads and still in the x264_macroblock_analyse(...) method.
Thread 1 is almost done and signals thread 2, then waits on thread 0 to signal in turn.
Thread 2 receives the green from thread 1 and goes on to call mb_info_free(...).
Thread 0 gets a SEGV if it checks for mb_info in the x264_macroblock_analyse(...).

A fix is for each thread to first wait  on the previous one to broadcast pass 2 (except for thread 0) then broadcast.

Please find a patch implementing the above attached at the end of this email.

Best,
Elias











NICE SRL, viale Monte Grappa 3/5, 20124 Milano, Italia, Registro delle Imprese di Milano Monza Brianza Lodi REA n. 2096882, Capitale Sociale: 10.329,14 EUR i.v., Cod. Fisc. e P.IVA 01133050052, Societa con Socio Unico




NICE SRL, viale Monte Grappa 3/5, 20124 Milano, Italia, Registro delle Imprese di Milano Monza Brianza Lodi REA n. 2096882, Capitale Sociale: 10.329,14 EUR i.v., Cod. Fisc. e P.IVA 01133050052, Societa con Socio Unico


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20231017/bd50237c/attachment.htm>


More information about the x264-devel mailing list