(chicken string)
matchable
srfi-18 ; threads
- srfi-69 ; hashtable
+ srfi-69 ; hash-table
udp
fifo)
(define (address-id address) (car address))
(define (address-machine address) (cdr address))
+(define (make-address id machine)
+ (cons id machine))
(define (address-local? address)
(equal? (address-machine address)
(define (make-actor beh)
(let* ((id next-actor-id))
- (hash-table-put! id beh)
- (cons id this-machine)))
+ (hash-table-set! actor-table id beh)
+ (make-address id this-machine)))
(define (deliver-message address . message)
(let ((id (address-id address)))
(match (apply (hash-table-ref actor-table id) (cons address message))
('done (hash-table-delete! actor-table actor))
('sleep 'do-nothing)
- (new-beh (hash-table-put! actor new-beh)))))))
+ (new-beh (hash-table-set! actor-table actor new-beh)))))))
;; Scheduler
(define (next-local-message)
(let ((res #f))
- (mutex-lock! message-available-mutex)
+ (mutex-lock! message-available-mutex #f #f)
(mutex-lock! local-queue-mutex)
(set! res (fifo-pop local-queue))
- (mutex-unlock! message-available-mutex)
+ (if (not (fifo-empty? local-queue))
+ (mutex-unlock! message-available-mutex))
(mutex-unlock! local-queue-mutex)
res))
(apply deliver-message next-addressed-message)
(loop (next-local-message))))))
+
+;; Testing
+
(thread-start! scheduler-thread)
+(define println
+ (make-actor (lambda (self . message)
+ (apply print message)
+ 'sleep)))
+
+(print println)
+(send-message println "Hello, world!")
+
(thread-join! scheduler-thread)