이 문제는 세마포(semaphore)라는 것을
뮤텍스(mutex)와 test-and-set! 프로시저를 이용하여 구현하는 문제입니다.

구현을 하기는 했지만 동작을 시키지 않아 어떤 문제점이 생길지 알 수 없습니다.
그 점이 아쉽습니다.
참조
해럴드 애빌슨, 김재우 역, <컴퓨터 프로그램의 구조와 해석>, 인사이트, 2007, pp. 407
; a
(define (make-semaphore n)
(let ((i 0)
(mutex (make-mutex)))
(define (the-semaphore m)
(cond ((eq? m 'acquire)
(set! i (+ i 1)) ; i 증가
(if (= i 0)
(mutex 'acquire))
(if (>= i n)
(mutex 'acquire))) ; retry
((eq? m 'release)
(set! i (- i 1)) ; i 감소
(if (>= i n)
(mutex 'release))
(if (= i 0)
(mutex 'release)))))
the-semaphore))
; b
(define (make-semaphore n)
(let ((i 0)
(cell (list false)))
(define (the-semaphore m)
(cond ((eq? m 'acquire)
(set! i (+ i 1)) ; i 증가
(if (>= i n)
(if (test-and-set! cell)
(the-semaphore 'loop)))) ; retry
((eq? m 'release)
(set! i (- i 1)) ; i 감소
(if (>= i n)
(clear! cell))
(if (= i 0)
(clear! cell)))
((eq? m 'loop)
(if (test-and-set! cell)
(the-semaphore 'loop)))))
the-semaphore))
- SICP Exercise 연습문제 3.51 (0)2008/07/19
- SICP Exercise 연습문제 3.50 (0)2008/07/19
- SICP Exercise 연습문제 3.48 (0)2008/07/18
- SICP Exercise 연습문제 3.47 (0)2008/07/18
- SICP Exercise 연습문제 3.46 (0)2008/07/18
- SICP Exercise 연습문제 3.44 (0)2008/07/17
- SICP Exercise 연습문제 3.43 (0)2008/07/17
글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.







댓글을 달아 주세요