my attempt to do the exercises in sicp.

Wednesday, March 24, 2010

sicp exercise 3.46


;; Exercise 3.46.  Suppose that we implement test-and-set! using an ordinary procedure as shown in the text, without attempting to make the operation atomic. Draw a timing diagram like the one in figure 3.29 to demonstrate how the mutex implementation can fail by allowing two processes to acquire the mutex at the same time.

;; Ans:
;; If the test-and-set! is not atomic, the while one process is checking its value to be false, other process can set the value to be true and take control of the mutex, while first process also does the same. So both processes acquire the mutex and enter the critical section. Which is not the desired behavior.

No comments: