pthread: Avoid spurious wakeups

pthread_wait_cond can wake up unexpectedly (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.

Test both cases to ensure the wakeup is real.

Signed-off-by: Ben Jackson <ben@ben.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Merge commit '5152196b2b47d446d9a509b9bfb318daa26a1f2b'

* commit '5152196b2b47d446d9a509b9bfb318daa26a1f2b':
  pthread: Avoid spurious wakeups

See: e3329474a366de066b25e86f35f5abf9c5a4b7b2
Merged-by: Michael Niedermayer <michaelni@gmx.at>