Skip to content

DSP_INIT can be called from multiple threads#46

Merged
NoXF merged 1 commit into
NoXF:masterfrom
deven96:diretnan/thread-safe-initialization
Apr 14, 2026
Merged

DSP_INIT can be called from multiple threads#46
NoXF merged 1 commit into
NoXF:masterfrom
deven96:diretnan/thread-safe-initialization

Conversation

@deven96
Copy link
Copy Markdown
Contributor

@deven96 deven96 commented Apr 9, 2026

I believe I ran into a case where multi-threaded programs get into VP8LDspInit concurrently and put the critical function pointers in a bad state which affects subsequent usage until program restart.

On this x86_64 system we have SSE and AVX2 available and ended up in a state where both VP8LPredictorsAdd[11] and VP8LPredictorsAdd_SSE[11] point to the same PredictorAdd11_AVX2 function leading to strange recursion and CPU saturation

A good case with a function pointers in a reasonable state looks like

sudo gdb -p ${pid} --batch \
-ex "set pagination off" \
-ex "print VP8LPredictorsAdd[11]" \
-ex "print VP8LPredictorsAdd_SSE[11]" \
-ex "print VP8LPredictorsAdd[11] == VP8LPredictorsAdd_SSE[11]" \
2>/dev/null

$1 = (VP8LPredictorsAddSubFunc) 0x55dc3dff7650 <PredictorAdd11_AVX2>
$2 = (VP8LPredictorsAddSubFunc) 0x55dc3dff8950 <PredictorAdd11_SSE2>
$3 = 0

Meanwhile a bad case looks like this

sudo gdb -p ${pid} --batch \
-ex "set pagination off" \
-ex "print VP8LPredictorsAdd[11]" \
-ex "print VP8LPredictorsAdd_SSE[11]" \
-ex "print VP8LPredictorsAdd[11] == VP8LPredictorsAdd_SSE[11]" \
2>/dev/null

$1 = (VP8LPredictorsAddSubFunc) 0x561e65724650 <PredictorAdd11_AVX2>
$2 = (VP8LPredictorsAddSubFunc) 0x561e65724650 <PredictorAdd11_AVX2>
$3 = 1

According to perf it seems to be stuck in PredictorAdd11_AVX2. So it seems to now call VP8LPredictorsAdd_SSE[11] for the remainder of the pixels which is just a pointer back to itself. I see that there exists the flag WEBP_USE_THREAD here supposed to enable threading support by enabling the pthread_mutex path during initialization.

@NoXF NoXF merged commit ef98846 into NoXF:master Apr 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants