[x264-devel] mb_info_free bug fix for sliced threads
Carotti, Elias
eliascrt at amazon.it
Mon Sep 11 13:56:15 UTC 2023
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20230911/5a178d53/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Prevent-mb_info_free-to-be-called-before-all-threads.patch
Type: application/octet-stream
Size: 1397 bytes
Desc: 0001-Prevent-mb_info_free-to-be-called-before-all-threads.patch
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20230911/5a178d53/attachment.obj>
More information about the x264-devel
mailing list