[FFmpeg-devel] [PATCH] Read |state| under the protection of |mutex| or |progress_mutex|.
Ronald S. Bultje
rsbultje at gmail.com
Fri Feb 26 21:16:15 CET 2016
Hi,
On Thu, Feb 25, 2016 at 9:18 PM, Wan-Teh Chang <wtc-at-google.com at ffmpeg.org
> wrote:
> Although not documented, |state| is guarded by either |mutex| or
> |progress_mutex|. In several places |state| is read without mutex
> protection, often as a double-checked locking style performance
> optimization. Fix the data races by reading |state| under mutex
> protection.
>
[..]
> - if (p->state != STATE_INPUT_READY) {
> - pthread_mutex_lock(&p->progress_mutex);
> - while (p->state != STATE_INPUT_READY)
> - pthread_cond_wait(&p->output_cond, &p->progress_mutex);
> - pthread_mutex_unlock(&p->progress_mutex);
> - }
> + pthread_mutex_lock(&p->progress_mutex);
> + while (p->state != STATE_INPUT_READY)
> + pthread_cond_wait(&p->output_cond, &p->progress_mutex);
> + pthread_mutex_unlock(&p->progress_mutex);
This will be slower, right? Is this an actual issue? Like, can you point to
cases like [1] (i.e. a real-world race condition with real-world
consequences) that were fixed with your patch?
Ronald
https://blogs.gnome.org/rbultje/2014/01/12/brute-force-thread-debugging/
More information about the ffmpeg-devel
mailing list