RosettaCodeData/Task/Synchronous-concurrency/Racket/synchronous-concurrency-1.rkt
2019-09-12 10:33:56 -07:00

17 lines
523 B
Racket

(define (reader)
(for ([line (in-lines (open-input-file "input.txt"))])
(thread-send printer-thread line))
(thread-send printer-thread eof)
(printf "Number of lines: ~a\n" (thread-receive)))
(define (printer)
(thread-send reader-thread
(for/sum ([line (in-producer thread-receive eof)])
(displayln line)
1)))
(define printer-thread (thread printer))
(define reader-thread (thread reader))
(for-each thread-wait
(list printer-thread reader-thread))