home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / aijournl / 1986_09 / cli.pcp < prev    next >
Text File  |  1986-06-07  |  2KB  |  69 lines

  1.  
  2. CLI LISP Producer-Consumer Problem
  3.  
  4.  
  5. ;; The Producer-Consumer Problem
  6. ;;       (synchronized)
  7. (defun pc ()
  8.   (setf buffer nil)
  9.   (setf information '(this is a test of semaphores))
  10.   ; initializes the semaphores
  11.   (initialize-semaphores '(($ok-to-consume 0) ($ok-to-produce 1)))
  12.   ; starts concurrent reading and writing.
  13.   (cobegin (list 'producer (length information))
  14.        (list 'consumer (length information)))
  15.   )
  16. (defun producer (r)
  17.   (do ((i 0 (1+ i)))
  18.       ((= i r) (print 'end-producer))
  19.     ; start of critical region
  20.     (wait '$ok-to-produce)
  21.     (print 'read-by-producer<---)
  22.     (setf buffer (nth i information))
  23.     (princ buffer)
  24.     (signal '$ok-to-consume)
  25.     ; end of critical region
  26.     )
  27. )
  28. (defun consumer (r)
  29.   (do ((i 0 (1+ i)))
  30.       ((= i r) (print 'end-consumer))
  31.     ; start of critical region
  32.     (wait '$ok-to-consume)
  33.     (print '----print-by-consumer--->)
  34.     (princ buffer)
  35.     (setf buffer nil)
  36.     (signal '$ok-to-produce)
  37.     ; end of critical region
  38.     )è)
  39. ;
  40. ;; The Producer-Consumer Problem
  41. ;;       (unsynchronized)
  42. (defun un-pc ()
  43.   (setf buffer nil)
  44.   (setf information '(this is a test of semaphores))
  45.   ;; starts concurrent reading and writing.
  46.   (cobegin (list 'un-producer (length information))
  47.        (list 'un-consumer (length information)))
  48. )
  49. (defun un-producer (r)
  50.   (do ((i 0 (1+ i)))
  51.       ((= i r) (print 'end-producer))
  52.     (print 'read-by-producer<---)
  53.     (setf buffer (nth i information))
  54.     (princ buffer)
  55.     (terpri)
  56.     )
  57. )
  58. (defun un-consumer (r)
  59.   (do ((i 0 (1+ i)))
  60.       ((= i r) (print 'end-consumer))
  61.     (print '----print-by-consumer--->)
  62.     (princ buffer)
  63.     (terpri)
  64.     (setf buffer nil)
  65.     )
  66. )
  67. ;
  68.  
  69.