[plt-scheme] Re: Shared resources for servlets

From: Keith Frost (keithf at amnis.com)
Date: Tue Sep 9 12:31:23 EDT 2003

If I'm not mistaken, you've answered your own question:  just use a 
module. 
When subsequent servlets 'require' the same module, it is not reloaded, and
any local state in the module is preserved.  If you need to serialize 
access to
resources controlled by the module, you can create a semaphore to do so
(see 'MzScheme Language Manual: Section 7.4'), so that servlets may block
while waiting for the resource to become available.

Which brings to mind a question I've had in the back of my mind, and I 
expect someone
on this list could help me with.  Consider the common resource model
"One writer -- many readers".  In other words, if a reader goes to 
access the resource,
it needs only check whether there is a writer accessing it.  If so, it 
blocks until the
writer releases it.  If not, it may go ahead, so that any number of 
readers can be
simultaneously accessing the resource (a database, or even a file, 
say).  If a writer
goes to access the resource, it has to check if there is another writer, 
or any readers,
currently accessing it.  If so, it blocks until all readers and any 
writer have released it.

What is the simplest, or a recommended, way to achieve this resource 
pattern using
MzScheme's threads and semaphores?



/ /




Posted on the users mailing list.