[vlc-devel] [PATCH 2/7] win32/inhibit: signal while holding the lock

Rémi Denis-Courmont remi at remlab.net
Tue Feb 4 11:25:41 CET 2020


Hi,

Nominally, signalling should be done with the lock held. It's more logical and it ensures that access to the internal state of the CV is serialised properly.

However some early uniprocessor implementations allegedly were faster if signalling was done after unlocking: the woken thread would preempt the signalling thread and attempt to lock the mutex. Thus it would go immediately back to sleep if the lock was still held by the signalling thread, and get preempt back again.

Le 4 février 2020 11:32:58 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>Personally I don't understand why the runtime would reorder 
>multithreading calls.
>
>But it seems more logical to do the unlock after the signal. Either it 
>worked by accident or supposedly because the runtime would reorder
>calls 
>? More info would be welcome.
>
>On 2020-02-04 10:11, Thomas Guillem wrote:
>> Indeed, OK for 2 and 3.
>> 
>> On Mon, Feb 3, 2020, at 22:13, Rémi Denis-Courmont wrote:
>>> This is the 21st century. The C run-time threading subsystem knows
>better
>>> than you how to optimise condition variables.
>>> ---
>>>   modules/video_output/win32/inhibit.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/modules/video_output/win32/inhibit.c
>>> b/modules/video_output/win32/inhibit.c
>>> index d23dcc33e4..566b311189 100644
>>> --- a/modules/video_output/win32/inhibit.c
>>> +++ b/modules/video_output/win32/inhibit.c
>>> @@ -42,8 +42,8 @@ static void Inhibit (vlc_inhibit_t *ih, unsigned
>mask)
>>>       vlc_inhibit_sys_t *sys = ih->p_sys;
>>>       vlc_mutex_lock(&sys->mutex);
>>>       sys->mask = mask;
>>> -    vlc_mutex_unlock(&sys->mutex);
>>>       vlc_cond_signal(&sys->cond);
>>> +    vlc_mutex_unlock(&sys->mutex);
>>>   }
>>>   
>>>   static void RestoreStateOnCancel( void* p_opaque )
>>> -- 
>>> 2.25.0
>>>
>>> _______________________________________________
>>> vlc-devel mailing list
>>> To unsubscribe or modify your subscription options:
>>> https://mailman.videolan.org/listinfo/vlc-devel
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>> 
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200204/6af7b718/attachment.html>


More information about the vlc-devel mailing list