Anonymous user
Synchronous concurrency: Difference between revisions
→{{header|Racket}}
Line 2,243:
Using thread mailboxes for communication between threads:
<lang racket>
(define (reader)
(for ([line (in-lines (open-input-file "input.txt"))])
Line 2,253 ⟶ 2,249:
(printf "Number of lines: ~a\n" (thread-receive)))
(define (printer)
(thread-send reader-thread
Line 2,261 ⟶ 2,255:
1)))
(define printer-thread (thread printer))
(define reader-thread (thread reader))
(for-each thread-wait
(list printer-thread reader-thread))
|