[vlc-devel] [PATCH] -- WIN32 endthreadex call

brezhoneg1 brezhoneg1 at yahoo.fr
Wed Feb 10 19:41:11 CET 2010


Sorry, for breaking the thread. There seems to be a email problem
somewhere since midday.
I'm no longer receiving anything from vlc. This is a cut&paste from the
web.

>Hello,
>
>On Wed, Feb 10, 2010 at 2:35 PM, brezhoneg1 <brezhoneg1 at yahoo.fr>
wrote:
>> Hi,
>>
>>  Please, find attached a few patches for which you may wish to
>> comment/object before applying them
>>
>> - patch1/patch2:
>>   on Win32, vlc thread management doesn't seem fully compliant with
>> msdn documentation.
>>   Those two patches should remedy this.
>
>Could you please share the link to the documentation page in which you
>read this? I can't find anywhere that _beginthreadex requires
>_endthreadex. Also,removing the handle duplication to avoid calling
>CloseHandle seems unsafe.



The problem with vlc threads is that there are two paths to terminate a
thread :

  - The normal path 
    In this case, _endthreadex is called implicitly when reaching the
end of the function.

  - Cancellation while waiting for a second thread to terminate
    Since vlc_join is a cancellation point, the thread can then exit
through the _endthread explicit call.
    (it does happen with the input thread IIRC)

The real problem is actually mixing _endthread and _endthreadex, since
one close the handler and the other one doesn't.
So I would rather use _endthreadex everywhere.

Also, on msdn, for _endthread, _endthreadex, it reads :

_endthread, _endthreadex 
Terminates a thread created by _beginthread or _beginthreadex,
respectively.


The second issue is the handle duplication.
Most of the time, the handle is not released, since we mostly terminate
threads with _endthreadex (the normal path)
I suspect that means a small memory leak (vlc never fully deallocates
handles). Not a big leak, but yet it's a leak.


I tested these patches successfully on WinXP. And I just realized one
more patch is needed for vlc_thread_create with the same issue.


Regards
Erwan10 





More information about the vlc-devel mailing list