skx has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Fellow Monks,
I believe I have an interesting problem with the implementation of the Singleton design pattern.
Essentially I'm trying to keep a cache of meta-data read from MP3 files, within a fork()ing server.
To do this I create a singleton "cache object" within the parent, then modify the contents of it within the child process.
Unfortunately my changes to the singleton object in the child processes are not reflected within the parent - So unsure how to proceed, I was under the impression that the singleton reference would be valid for both.
This is my creation code:
my $oneTrueSelf; sub new { if($oneTrueSelf) { return $oneTrueSelf; } else { my $type = shift; my $this = {} $oneTrueSelf = bless $this, $type; return $this->new(); } }
Is there an obvious way to proceed? Or do I have to brave the scary shared memory magic?
Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The Singleton design pattern and fork();
by tall_man (Parson) on Feb 22, 2003 at 05:38 UTC | |
by skx (Parson) on Feb 22, 2003 at 05:47 UTC | |
|
Re: The Singleton design pattern and fork();
by Zaxo (Archbishop) on Feb 22, 2003 at 05:42 UTC | |
|
Re: The Singleton design pattern and fork();
by BrowserUk (Patriarch) on Feb 22, 2003 at 10:17 UTC | |
by hossman (Prior) on Feb 22, 2003 at 11:27 UTC | |
by BrowserUk (Patriarch) on Feb 22, 2003 at 12:46 UTC | |
|
Re: The Singleton design pattern and fork();
by diotalevi (Canon) on Feb 22, 2003 at 07:12 UTC | |
by skx (Parson) on Feb 22, 2003 at 17:23 UTC | |
|
Re: The Singleton design pattern and fork();
by mowgli (Friar) on Feb 22, 2003 at 10:35 UTC |