NAME
Thread::IID - unique perl Interpreter IDs
VERSION
version 0.02
SYNOPSIS
use Thread::IID ':all';
print "Hi, I am interpreter #" . interpreter_id;
DESCRIPTION
This provides an identifier to distinguish Perl interpreter instances.
In environments like mod_perl2, where interpreters can be cloned and passed around between OS threads, the thread ID gives no indication of which interpreter instance is actually running and hence which corresponding set of values/data-structures is actually being referenced. For such situations the interpreter ID is more likely to be what you actually want.
EXPORT
None by default. The following function is available:
interpreter_id()
Returns an (integer) ID for this instance of the perl interpreter.
Where multiple interpreters have been created to run in threads of the current process, the IDs returned will be distinct for each interpreter, regardless of which threads are running which interpreters.
It is possible (and likely in the case a fork()
has occurred) that this will return the same ID for interpreters in different processes.
EXAMPLE
In the following
my @value = (0, interpreter_id, $$, time);
sleep(1);
sub counter {
++$value[0];
return @value;
}
counter()
is guaranteed to return a list value distinct from all other invocations in all processes/threads that are running this code on a given host.
AUTHOR
Packaged by Roger Crew <crew@cs.stanford.edu>.
Original XS code is from a posting by ikegami at PerlMonks.
COPYRIGHT AND LICENSE
Copyright (C) 2011 by Roger Crew.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.