examples/example-2.ss
#lang scheme/base
; Example 2 - Resources

(require (planet "simulation.ss" ("williams" "simulation.plt")))
(require (planet "random-distributions.ss"
                 ("williams" "science.plt")))

(define n-attendants 2)
(define attendant #f)

(define-process (generator n)
  (do ((i 0 (+ i 1)))
      ((= i n) (void))
    (wait (random-exponential 4.0))
    (schedule now (customer i))))

(define-process (customer i)
  (printf "~a: customer ~a enters~n" (current-simulation-time) i)
  (request attendant)
  (printf "~a: customer ~a gets an attendant~n" (current-simulation-time) i)
  (work (random-flat 2.0 10.0))
  (relinquish attendant)
  (printf "~a: customer ~a leaves~n" (current-simulation-time) i))

(define (run-simulation n)
  (with-new-simulation-environment
   (set! attendant (make-resource n-attendants))
   (schedule (at 0.0) (generator n))
   (start-simulation)))

(run-simulation 10)