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

Romain Vimont rom1v at videolabs.io
Fri Mar 20 17:17:57 CET 2020



On 3/20/20 1:48 PM, Rémi Denis-Courmont wrote:
> Le torstaina 19. maaliskuuta 2020, 20.44.03 EET Marvin Scholz a écrit :
>> +static void *thread_func_cond_states(void *ptr)
>> +{
>> +    struct cond_data *data = ptr;
>> +
>> +    // 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);
>> +
>> +    // 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);
> 
> The thread is signalling its own self and presumably locking dead.

The test looks good to me:
  - thread 1 initializes state to 0 and waits until it is set to 1
  - thread 2 sets it to 1, signals and waits until it is set to 2
  - thread 1 sets it to 2, signals, and join
  - thread 2 will finish

>> +    }
>> +    vlc_cleanup_pop();
>> +    vlc_mutex_unlock(&data->mutex);
>> +
>> +    return &thread_return_magic;
>> +}

>> +    // Test thread waiting on condition
>> +    {
>> +        struct cond_data data;
>> +        data.state = 0;
>> +        vlc_mutex_init(&data.mutex);
>> +        vlc_cond_init(&data.cond);
>> +
>> +        vlc_thread_t th;
>> +        TEST_THREAD_CLONE(&th, thread_func_cond_states, &data);
>> +
>> +        // 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);
>> +
>> +        // Change to state 2
>> +        vlc_mutex_lock(&data.mutex);
>> +        data.state = 2;
>> +        vlc_cond_signal(&data.cond);
>> +        vlc_mutex_unlock(&data.mutex);
>> +
>> +        // Wait for thread exit
>> +        TEST_THREAD_JOIN_MAGIC(th);
>> +    }


More information about the vlc-devel mailing list