lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2011/11/10 Philipp Janda <siffiejoe@gmx.net>:
> On 10.11.2011 12:04, Benoit Germain wrote:
>
> That would probably work, but an easier way would be:
> static void* lane_main( void* vs ) {
>  pthread_cleanup_push( free, vs ); // handles cancels and exits
>
>  // code ...
>
>  pthread_cleanup_pop( TRUE ); // handles reaching end of lane_main
>  return 0;
> }
>
> That would pop and call 'free( vs )' automatically when/if the thread is
> cancelled or calls pthread_exit. 'pthread_cleanup_pop( TRUE )' pops and
> calls 'free( vs )' manually if the execution reaches the end of lane_main.

We don't want to do this (freeing the structure as soon as the thread
terminates). We have to do this only after the lane userdata is GC'ed,
else we can't be sure another Lua state won't want to retrieve the
return values of the lanes's function. THREAD_KILL at main state's GC
is a last attempt to do things right (mainly freeing the lane
structure, which involves stopping the execution of the associated
thread).

> The crash happens in one of the print()s. If I comment them out the crash goes away. I think one cancelled thread leaves stdio in an invalid state.

I'd say: let's fix the first bug, just in case this one is a side effect.


-- 
Benoit.