Structure and Interpretation of Computer Programs, Second Edition by Harold Abelson Gerald Jay Sussman Julie Sussman

Structure and Interpretation of Computer Programs, Second Edition by Harold Abelson Gerald Jay Sussman Julie Sussman

Author:Harold Abelson, Gerald Jay Sussman, Julie Sussman
Language: eng
Format: epub, pdf
Publisher: MIT Press
Published: 1996-06-10T16:00:00+00:00


Then deposits are handled as with the original make-account:

(define (deposit account amount) ((account 'deposit) amount))

Explain what is wrong with Louis’s reasoning. In particular, consider what happens when serialized-exchange is called.

Implementing serializers

We implement serializers in terms of a more primitive synchronization mechanism called a mutex. A mutex is an object that supports two operations—the mutex can be acquired, and the mutex can be released. Once a mutex has been acquired, no other acquire operations on that mutex may proceed until the mutex is released.172 In our implementation, each serializer has an associated mutex. Given a procedure p, the serializer returns a procedure that acquires the mutex, runs p, and then releases the mutex. This ensures that only one of the procedures produced by the serializer can be running at once, which is precisely the serialization property that we need to guarantee.

(define (make-serializer) (let ((mutex (make-mutex))) (lambda (p) (define (serialized-p . args) (mutex 'acquire) (let ((val (apply p args))) (mutex 'release) val)) serialized-p)))



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.