I found another problem in w32pthread.h.

//libavcodec\w32pthreads.h
static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
    win32_cond_t *win32_cond = cond->ptr;
    if (cond_wait) {
        cond_wait(cond, mutex, INFINITE);
        return;
    }

    /* non native condition variables */
    pthread_mutex_lock(&win32_cond->mtx_waiter_count);
    win32_cond->waiter_count++;
    pthread_mutex_unlock(&win32_cond->mtx_waiter_count);

    pthread_mutex_unlock(mutex);
    WaitForSingleObject(win32_cond->semaphore, INFINITE);
    pthread_mutex_lock(mutex);
}


//libavcodec/pthread.c
static void* attribute_align_arg worker(void *v)
{
//<...skipped...>
        while (our_job >= c->job_count) {
            if (c->current_job == thread_count + c->job_count)
                pthread_cond_signal(&c->last_job_cond);

            pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
            our_job = self_id;

            if (c->done) {
                pthread_mutex_unlock(&c->current_job_lock);
                return NULL;
            }
        }
//<...skipped...>
}


pthread_cond_wait will call WaitForSingleObject(win32_cond->semaphore); but
ReleaseSemaphore(win32_cond->semaphore) is never called ...


2011/12/7 Ronald S. Bultje <[email protected]>

> Hi,
>
> On Dec 6, 2011 6:06 PM, "Uoti Urpala" <[email protected]> wrote:
> >
> > On Tue, 2011-12-06 at 22:18 +0700, Sergey Radionov wrote:
> > > Reason for making this patch
> > > is https://trac.videolan.org/vlc/ticket/5571
> > >
> > >
> > > Problem is that under windows, when multiple threads waiting on same
> > > semaphore, and when ReleaseSemaphore called, it impossible to predict
> > > wich thread will wake up...
> >
> > The pthread_cond_broadcast() implementation in w32pthreads.h looks
> > suspicious - it could wake up the same thread multiple times (if it
> > re-enters wait fast enough) instead of waking up all current waiters.
> > Maybe that is the actual problem?
>
> If that's the case grabbing and directly releasing a static lock in
> pthread_mutex_lock, and holding this in pthread_cond_broadcast, should fix
> it.
>
> Ronald
>
> _______________________________________________
> libav-devel mailing list
> [email protected]
> https://lists.libav.org/mailman/listinfo/libav-devel
>
>
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to