Synchronous concurrency: Difference between revisions

Line 2,256:
;; 2) Send the total number of lines printed to the Reader thread.
(define (printer)
(thread-send reader-thread
(let loop ([line (thread-receive)][count 0])
(for/sum ([line (in-producer thread-receive eof)])
(if (eof-object? line)
(thread-sendprintf reader-thread"~a\n" countline)
(begin 1)))
(printf "~a\n" line)
(loop (thread-receive) (add1 count))))))
 
;; Start both threads
Anonymous user