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

Andrej N. Gritsenko andrej at rep.kiev.ua
Mon Jan 2 22:59:59 CET 2012


    Hello!

Dan Oscarsson has written:
>Attached is a new version of my threaded cache code.

>This version does not have a sleep or timed wait in the cache thread.
>configure need more work, I expect some of you know better then me how
>you want it.

[.......]
>+#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.

    With best wishes.
    Andriy.


More information about the MPlayer-dev-eng mailing list