[FFmpeg-devel] [PATCH] pthread: Avoid crashes/odd behavior caused by spurious wakeups

Ben Jackson ben at ben.com
Thu Sep 13 20:35:24 CEST 2012


On Wed, Sep 12, 2012 at 01:31:35AM -0700, Ben Jackson wrote:
> pthread_wait_cond can wake up for no reason (Wikipedia: Spurious_wakeup).
> The FF_THREAD_SLICE thread mechanism could spontaneously execute jobs or
> allow the caller of avctx->execute to return before all jobs were complete.
> This adds tests to both cases to ensure the wakeup is real.

Ping?

I hoped to put enough explanation in the commit message without being too
verbose, but I'm happy to provide more detail.  The Wikipedia page is
informative.

I've got a patch I'm waiting to submit that adds threading to VP6A decode,
but I tripped over this pthread problem while working on it so I wanted
to get the pthread patch accepted first.  The user-visible problem was
intermittent segmentation faults if I hit ctrl-C during a decode.  An
asynchronous signal like SIGINT can go to any thread.  If it's delivered
to a thread that's in pthread_cond_wait that wait can (or possibly *will*)
wake up spuriously.  I hit this on FreeBSD but I believe the same is
true on Linux.  Other decoders are probably vulnerable to this if they
support slice threading, but they might not all crash if execute returns
too soon or if a worker executes a spontaneous job.

-- 
Ben Jackson AD7GD
<ben at ben.com>
http://www.ben.com/


More information about the ffmpeg-devel mailing list