[vlc-devel] [PATCH] test: add thread test

Alexandre Janniaux ajanni at videolabs.io
Fri Mar 20 17:31:02 CET 2020


Hi,

I don't understand the issue, like Romain there is four critical area
so it should be easy to define the possible interleavings:

First two in the first thread:


A:

    // Change to state 1
    vlc_mutex_lock(&data->mutex);
    assert(data->state == 0);
    data->state = 1;
    vlc_cond_signal(&data->cond);
    vlc_mutex_unlock(&data->mutex);

B:

    // Wait for state 2
    vlc_mutex_lock(&data->mutex);
    mutex_cleanup_push(&data->mutex);
    while(data->state != 2) {
        vlc_cond_wait(&data->cond, &data->mutex);
    }
    vlc_cleanup_pop();
    vlc_mutex_unlock(&data->mutex);

The other in the main thread:

C:

    // Wait for state 1
    vlc_mutex_lock(&data.mutex);
    while(data.state != 1) {
        vlc_cond_wait(&data.cond, &data.mutex);
    }
    vlc_mutex_unlock(&data.mutex);

D:

    // Change to state 2
    vlc_mutex_lock(&data.mutex);
    data.state = 2;
    vlc_cond_signal(&data.cond);
    vlc_mutex_unlock(&data.mutex);

You also have the following happens-before:

A -> B
C -> D

As far as I understand, the only possible interleaving are then:

ABCD
ACBD
ACDB
CDAB
CADB
CABD

In any of them, the situation seems pretty clear and it looks like
a normal barrier.

There is no code between the critical area, and only one lock, so
where would this race come from?

Regards,
--
Alexandre Janniaux
Videolabs

On Fri, Mar 20, 2020 at 05:30:16PM +0200, Rémi Denis-Courmont wrote:
> Le perjantaina 20. maaliskuuta 2020, 17.09.51 EET Marvin Scholz a écrit :
> > > The thread is signalling its own self and presumably locking dead.
> >
> > The intent of this is that the main thread waits for the change of
> > state to 1 (changed in this thread) and then this thread waits for the
> > state change to 2 (changed in the main thread).
> > Won’t that work? Maybe I overlook something.
>
> The test is racy. It probably works with the current implementation of the VLC
> back-end but that's just an implementation detail.
>
> --
> Реми Дёни-Курмон
> http://www.remlab.net/
>
>
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list