Re: A global has among threads
From: Nicholas Dronen (ndronen_at_io.frii.com)
Date: 27 Oct 2003 04:56:17 GMT
Mark <email@example.com> wrote:
M> Is there a way I can uses a global hash within Perl (5.8.0) with threads?
M> The reason I ask, is that I have a Milter (Sendmail::Milter) running, which
M> is a daemonized version of Perl 5.8.0 with threads enabled. I would like to
M> maintain a global hash of hostnames who have already been looked up
M> previously, so as to avoid renewed DNS queries.
M> Short of resorting to using shmget and all the other shared memory stuff, I
M> was wondering whether there is ANY way to maintain a global hash, shared
M> among all threads?
If the occasional bad record doesn't concern you, ignore this post.
One thing to keep in mind is that, unless your daemon respects the
TTL, a simple host name -> address cache will become invalid when
a changed record expires.
A module like Net::DNSServer might be inappropriate for your threaded
daemon, but at least it'd handle TTL for you:
Other possibilities are running a caching-only DNS server on the
machines that run your daemon, or writing TTL-aware code into your
-- "Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html "Meanings are another story." http://www.ifas.org/wa/glossolalia.html