Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

There are two problems with the idea.

  1. I've never managed to work out how to use the value returned from _handle().

    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.

  2. Terminating threads is a desperate measure as it does not allow either the thread itself, the OS, or Perl to clean up after themselves, leading to a massive memory leak. Not to mention the potential for all sorts of nasties with dangling pointers etc.

    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.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

In reply to Re^4: Locked threads and tcp timeouts by BrowserUk
in thread Locked threads and tcp timeouts by menth0l

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [ambrus]: Corion: for electronics, amazon is probably better, depending on your geographic location (definitely better in the US)
    [ambrus]: at least high-end electronics
    [ambrus]: both new and used
    [marto]: anyone have a Ryzen CPU?
    [moritz]: it's not even on the Ho-Ryzen for me :-)
    [choroba]: :-D moritz++ # it's not even on the Ho-Ryzen for me

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (12)
    As of 2017-11-21 15:17 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (304 votes). Check out past polls.