in reply to Re^3: How do I get a unique Perl Interpreter ID?
in thread How do I get a unique Perl Interpreter ID?
If you've moved away from staying pure Perl, for a source of an unguessable counter, I'd use the Time Stamp Counter.Various things:
I think as long as I've got time() in there we're okay (.. and I believe it's bullet-proof if I put in a sleep(1) between initializing the counter and creating the sub ...hmmm... and now we may have an argument for using microtime...)is that I get what looks like a proof of the impossibility of two counter invocations producing the same result. I figure that beats 4 aces and any amount of futuristic hardware (... meaning we're set for another 10 years at least...).
Fleshing this out a bit more just to make the idea clear:
sleep(1.1); $t=time(); sleep(1.1);
my @value = (0,interpreter_id(),$$,$t);
sub counter { ++$value[0]; return @value; }
that first line blocks out a time interval 2.2 seconds long during which every other interpreter instance on the same host other than the one that's sleeping must have either a different interpreter_id or a different $$ (since for something to have the same interpreter_id, which is really a memory address, either it's sharing the same PerlInterpreter structure and hence is same interpreter, or it must be in a different address space, which means it's in a different process, and therefore must have a different $$ because it's in existence concurrently with the process containing the sleeping interpreter).And yes, I know proofs are only as good the axioms; it's very easy to make stupid assumptions in this realm, and over the years I've seen lots of these fall over...
On the other hand, this is the best I've seen in a while, so I think I'm going to run with it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How do I get a unique Perl Interpreter ID?
by BrowserUk (Patriarch) on Dec 06, 2011 at 20:05 UTC |