<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1">
<TITLE>Re: Shared resources for servlets</TITLE>
</HEAD>
<BODY dir=ltr>
<DIV>Here's a quck draft (probably would need a bit of debugging, I have no
DrScheme on this machine):<BR></DIV>
<DIV><FONT face="Courier New">(module lock mzscheme</FONT></DIV>
<DIV><FONT face="Courier New"> (define read/write-object</FONT></DIV>
<DIV><FONT face="Courier New"> (class</FONT></DIV>
<DIV><FONT face="Courier New"> (define (read)
'todo)</FONT></DIV>
<DIV><FONT face="Courier New"> (define (write
to-write) 'todo)))</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> (define lockable-object</FONT></DIV>
<DIV><FONT face="Courier New"> (class</FONT></DIV>
<DIV><FONT face="Courier New"> (define reading
0)</FONT></DIV>
<DIV><FONT face="Courier New"> (define wrin</FONT><FONT
face="Courier New">ing? #f)</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">
(init-field obj)</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> (define
(open-read)</FONT></DIV>
<DIV><FONT face="Courier New"> (if
writing?</FONT></DIV>
<DIV><FONT face="Courier New">
(begin (sleep) (open-read))</FONT></DIV>
<DIV><FONT face="Courier New">
(set! reading (+ reading 1))))</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> (define
(close-read)</FONT></DIV>
<DIV><FONT face="Courier New"> (set!
reading (- reading 1)))</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> (define
(open-write)</FONT></DIV>
<DIV><FONT face="Courier New"> (if (or
writing? (> reading 0))</FONT></DIV>
<DIV><FONT face="Courier New">
(begin (sleep) (open-write))</FONT></DIV>
<DIV><FONT face="Courier New">
(set! writing? #t)))<BR></FONT></DIV>
<DIV><FONT face="Courier New"> (define
(close-write)</FONT></DIV>
<DIV><FONT face="Courier New"> (set!
writing? #f))</FONT></DIV>
<DIV><FONT face="Courier New"> </DIV></FONT>
<DIV><FONT face="Courier New"> (define
(read)</FONT></DIV>
<DIV><FONT face="Courier New"> ; returns
current value.</FONT></DIV>
<DIV><FONT face="Courier New">
; Copies it first so it doesn't change when writing later on</FONT></DIV>
<DIV><FONT face="Courier New">
(open-read)</FONT></DIV>
<DIV><FONT face="Courier New"> (let ([r
(send obj read)])</FONT></DIV>
<DIV><FONT face="Courier New">
(close-read)</FONT></DIV>
<DIV><FONT
face="Courier New">
r)))</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> (define (write
to-write)</FONT></DIV>
<DIV><FONT face="Courier New">
(open-write)</FONT></DIV>
<DIV><FONT face="Courier New"> (send
obj write to-write)</FONT></DIV>
<DIV><FONT face="Courier New">
(close-write)))))</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face=Arial>Now all you have to do is fill in (read) and (write
to-write) in read/write-object.</FONT></DIV>
<DIV><FONT face=Arial>(define lo (instantiate lockable-object () [obj
'insert-read/write-object-here]))</FONT></DIV>
<DIV><FONT face=Arial>(send lo read)</FONT></DIV>
<DIV><FONT face=Arial>(send lo write 'value)</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>-----Original Message----- <BR><B>From:</B> Keith Frost
[mailto:keithf@amnis.com] <BR><B>Sent:</B> ג 09/09/2003 22:40 <BR><B>To:</B> Dor
Kleiman <BR><B>Cc:</B> plt-scheme@list.cs.brown.edu <BR><B>Subject:</B> Re:
Shared resources for servlets<BR><BR></DIV></FONT>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P><FONT size=2>Dor Kleiman wrote:<BR><BR>> I'm not sure that would
work.<BR>> Consider this:<BR>> 3 readers are reading. A writer comes and
blocks. Then a reader comes<BR>> and joins in, blocking the writer even
longer. This could block<BR>> indefinitely, which won't be very good, would
it?<BR><BR>Well, this is a simple model. You point out that it has the
problem<BR>that writers can be denied service indefinitely, if there is a
sufficient<BR>volume of readers. This is true. One can devise a
more complex<BR>model, such as one where (for example) a writer sends a
request,<BR>and new readers are blocked until that request is satisfied.
But first,<BR>I just want to know how to implement the simple
model!<BR><BR>Keith<BR><BR><BR></FONT></P></BLOCKQUOTE>
</BODY>
</HTML>