[plt-scheme] RE: Shared resources for servlets

From: Dor Kleiman (dor at ntr.co.il)
Date: Wed Sep 10 16:45:35 EDT 2003

Well it's not perfect because it's just an abstraction. It doesn't deal with exceptions, for one.
I have one questions though:
Do the threads not wait to their turn and only change at (sleep)s and blocks?
If so, all the race conditions would not happen

	-----Original Message----- 
	From: Joe Marshall [mailto:jrm at ccs.neu.edu] 
	Sent: ד 10/09/2003 20:21 
	To: Dor Kleiman; Keith Frost 
	Cc: plt-scheme at list.cs.brown.edu 
	Subject: Re: [plt-scheme] RE: Shared resources for servlets

	Re: Shared resources for servletsFrom:  Dor Kleiman <dor at ntr.co.il>;
	To:  Keith Frost <keithf at amnis.com>
	> (module lock mzscheme
	>   (define read/write-object
	>     (class
	>       (define (read) 'todo)
	>       (define (write to-write) 'todo)))
	>   (define lockable-object
	>     (class
	>       (define reading 0)
	>       (define writing? #f)
	>       (init-field obj)
	>       (define (open-read)
	>         (if writing?
	>             (begin (sleep) (open-read))
	>             (set! reading (+ reading 1))))
	Race condition here, writing? could be #F when
	conditional is tested, but changed to #T before
	reading is incremented.
	Additionally, reading is not atomically incremented,
	so an increment could be lost.
	>       (define (close-read)
	>         (set! reading (- reading 1)))
	Could lose the decrement on a race condition.
	>       (define (open-write)
	>         (if (or writing? (> reading 0))
	>             (begin (sleep) (open-write))
	>             (set! writing? #t)))
	Again, race condition in the conditional, two processes
	could both detect no writing? condition and each think
	that it can write.
	>       (define (close-write)
	>         (set! writing? #f))
	>       (define (read)
	>         ; returns current value.
	>         ; Copies it first so it doesn't change when writing later on
	>         (open-read)
	>         (let ([r (send obj read)])
	>           (close-read)
	>           r)))
	Need a dynamic-wind here to ensure that the lock is freed
	even if the reader aborts.
	>       (define (write to-write)
	>         (open-write)
	>         (send obj write to-write)
	>         (close-write)))))
	Need a dynamic-wind here to ensure that the lock is freed
	even if the writer aborts.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030910/3a6d2c4c/attachment.html>

Posted on the users mailing list.