in reply to How do I get a unique Perl Interpreter ID?

use strict; use warnings; use feature qw( say ); use Inline C => <<'__EOI__'; IV get_interpreter_id() { return (IV)PERL_GET_THX; } __EOI__ say get_interpreter_id();
>perl a.pl 3092452

(Also perl -MInline=FORCE,NOISY,NOCLEAN a.pl)

The XS is simply

#include "EXTERN.h" #include "perl.h" #include "XSUB.h" MODULE = Foo PACKAGE = Foo IV get_interpreter_id() CODE: RETVAL = (IV)PERL_GET_THX; OUTPUT: RETVAL

Replies are listed 'Best First'.
Re^2: How do I get a unique Perl Interpreter ID?
by wrog (Friar) on Dec 02, 2011 at 21:42 UTC
    okay, this, with some minor changes, now exists as Thread::IID:
    • (UV) instead of (IV).
    • left off the 'get_'
    • returns PERL_GET_THX>>11 because PerlInterpreter structures are Just Huge (2800 bytes in my world) and this reduces the returned numbers somewhat.
    Enjoy. And thanks.