[MPlayer-dev-eng] threaded cache, round 2

Dan Oscarsson Dan.Oscarsson at tieto.com
Tue Jan 3 09:47:38 CET 2012


mån 2012-01-02 klockan 23:59 +0200 skrev Andrej N. Gritsenko:
> [.......]
> >+#ifdef PTHREAD_CACHE
> >+    if (!((cache_vars_t *)s->cache_data)->do_work) {
> >+        pthread_mutex_lock(&((cache_vars_t *)s->cache_data)->go_ahead_mutex);
> >+           ((cache_vars_t *)s->cache_data)->do_work = 1;
> >+        pthread_mutex_unlock(&((cache_vars_t *)s->cache_data)->go_ahead_mutex);
> >+        pthread_cond_signal(&((cache_vars_t *)s->cache_data)->go_ahead);
> >+    } else {
> >+        // when cache_do_control loops on the cpu, sometimes system is slow
> >+        // to wake up threads. A quick sleep helps
> >+        usec_sleep(1);
> >+    }
> >+#endif
> >+
> [.......]
> 
>     Is it change on do_work possible only in one thread? If not then you
> should lock mutex before conditional based on its value. And as soon it's
> set to 1 in one thread and to 0 in another (assuming from you code) that
> means your code contains race condition, i.e. mutex locking is really not
> functional so you have to fix that everywhere.

Main thread sets do_work to 1 to tell cache that main thread have read
data from cache or a command is available to be processed. And main
thread does this after it has read data from cache or set up command. I
do not think there can be a race condition.

   Dan



More information about the MPlayer-dev-eng mailing list