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

Michael Niedermayer michaelni at gmx.at
Tue Oct 22 13:41:36 CEST 2013


On Tue, Oct 22, 2013 at 12:02:44PM +0100, Derek Buitenhuis wrote:
> This is similar to e3329474a366de066b25e86f35f5abf9c5a4b7b2.
> 
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
>  libavfilter/pthread.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
> index 8ae2c3f..91fb4c6 100644
> --- a/libavfilter/pthread.c
> +++ b/libavfilter/pthread.c
> @@ -58,6 +58,7 @@ typedef struct ThreadContext {
>      pthread_cond_t current_job_cond;
>      pthread_mutex_t current_job_lock;
>      int current_job;
> +    unsigned int current_execute;
>      int done;
>  } ThreadContext;
>  
> @@ -66,6 +67,7 @@ static void* attribute_align_arg worker(void *v)
>      ThreadContext *c = v;
>      int our_job      = c->nb_jobs;
>      int nb_threads   = c->nb_threads;
> +    int last_execute = 0;
>      int self_id;
>  
>      pthread_mutex_lock(&c->current_job_lock);
> @@ -75,8 +77,9 @@ static void* attribute_align_arg worker(void *v)
>              if (c->current_job == nb_threads + c->nb_jobs)
>                  pthread_cond_signal(&c->last_job_cond);
>  
> -            if (!c->done)
> +            while (last_execute == c->current_execute && !c->done)
>                  pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
> +            last_execute = c->current_execute;
>              our_job = self_id;
>  
>              if (c->done) {
> @@ -113,7 +116,8 @@ static void slice_thread_uninit(ThreadContext *c)
>  
>  static void slice_thread_park_workers(ThreadContext *c)
>  {
> -    pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
> +    while (c->current_job != thread_count + c->job_count)

this still does not build

ThreadContext doesnt have a job_count nor is there a local thread_count

libavfilter/pthread.c: In function ‘slice_thread_park_workers’:
libavfilter/pthread.c:119:30: error: ‘thread_count’ undeclared (first use in this function)
libavfilter/pthread.c:119:30: note: each undeclared identifier is reported only once for each function it appears in
libavfilter/pthread.c:119:46: error: ‘ThreadContext’ has no member named ‘job_count’

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131022/a39e0de7/attachment.asc>


More information about the ffmpeg-devel mailing list