Re: [AD] 4.9/src/win/wxthread.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2009-03-14, AJ <aj@xxxxxxxxxx> wrote:
> 
> the original issue i raised was just the thread handle problem, which 
> the _beginthreadex()  does not appear to have, so simply using that 
> instead of the non-ex   _beginthread()  should solve our problem without 
> introducing a bunch of new issues.
> 
> the only major change  the ex() adds is that you need to need to call  
> _endthreadex()

I don't think it's *required*:

    _endthread or _endthreadex is called automatically when the thread
    returns from the routine passed as a parameter. Terminating a thread
    with a call to endthread or _endthreadex helps to ensure proper
    recovery of resources allocated for the thread.

> the minor changes are the return values are different, and the calling 
> convention on the trampoline needs to be changed to __stdcall
> 
> i dont see any problem in changing our code to use _beginthreadex()   it 
> now seems fairly straight forward.

This was a bit concerning:

    However, the handle returned by _beginthreadex has to be closed by
    the caller of _beginthreadex,

It suggests that only the thread that called _beginthreadex() can close
the handle.  It's probably (hopefully) just badly worded, as it would
conflict with our public thread API, which has no such requirement.

> the new trampoline would be like:
> 
> static unsigned int __stdcall trampoline( ... )
> {
>     .... existing code ....
>     _endthreadex( 0 );
>      return 0;
> }
> 
> 
> we also need to manually close the handle with a   CloseHandle( h );
> not sure were this should go?
> perhaps in the _al_thread_join()  ?  

Yes.

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/