in reply to Re^3: Locked threads and tcp timeouts
in thread Locked threads and tcp timeouts
There are two problems with the idea.
It appears to be returned in the IV slot of the SV:
SV = IV(0x3afb470) at 0x3afb478 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 94514760
but all my attempts to use it from XS in calls to the OS result in The handle is invalid.
If you bypass the first problem by calling an XS sub that gets the current thread handle from the OS -- which isn't very useful as it can only be called from within the thread to be killed -- and run a loop that creates threads and has them self terminate, then you see the scope of the massive memory leak it creates:
#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'TerminateThreadTest', CLEAN_AFTER +_BUILD => 0; int killThread( SV *t, SV *ec ) { printf( "t:%p ec:%d\n", SvIV( t ), SvIV( ec ) ); return TerminateThread( SvIV( t ), SvIV( ec ) ); } void hariKari( SV *exitCode ) { TerminateThread( GetCurrentThread(), SvIV( exitCode ) ); } END_C use Devel::Peek; use threads; for( 1 .. 100 ) { my $t = async { sleep 5; hariKari( 12345 ); }; sleep 10; }
On my system, the above script leaks around 2MB for every thread killed. Whilst that could be reduce by spawning early and trimming the stack etc., it will never be zero.
|
|---|