Hello,

RR>I'm needing to implement a handler that uses a true Singleton pattern for
RR>the class instance. One per server, not just one per process (or thread).

SL>You'll need to use some form of persistance mechanism such as a
SL>database, file, or perhaps (assuming you're on a Unix system)
SL>something like System V shared memory or semaphores.

You can find more information on maintaining server-side state in the
mod_perl guide or from the mod_perl book (at perl.apache.org and
www.modperl.com, respectively).

SL>One quick 'n cheap way to implement mutual exclusion between Unix
SL>processes (executing on the same processor) is to use mkdir, which is
SL>atomic (ie once a process requests a mkdir, the mkdir will either be
SL>done or rejected before the requesting process is preempted by any
SL>other process).

IMO, this is sort of cumbersome; on a single processor, you can just use
advisory file locking. It's when you get onto NFS mounted systems with
high concurrency that you have to muck with rolling your own mutexes (I
find I usually use atomic move for that purpose). But on a single system,
use flock() and a known lockfile, or sysopen with O_CREAT|O_EXCL if you
can't put the file there beforehand.

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       [EMAIL PROTECTED]
Engineer                   [EMAIL PROTECTED]          Voice 650-930-9062
Tellme Networks, Inc.       1-800-555-TELL            Fax 650-930-9101
----------------------------------------------------------------------

Reply via email to