racket/system: add some missing synchronization

These changes are intended to address "input port is closed" errors
that have been showing up with Racket CS, possibly because its
scheduler exposed missing synchronization.
This commit is contained in:
Matthew Flatt 2019-05-27 10:39:19 -06:00
parent 0bffb7035d
commit 40846e3ed9
2 changed files with 15 additions and 12 deletions

View File

@ -25,17 +25,19 @@
(define (streamify-in cin in ready-for-break) (define (streamify-in cin in ready-for-break)
(if (and cin (not (file-stream-port? cin))) (if (and cin (not (file-stream-port? cin)))
(thread (lambda () (parameterize-break #f
(dynamic-wind (thread (lambda ()
void (dynamic-wind
(lambda () void
(with-handlers ([exn:break? void]) (lambda ()
(ready-for-break #t) (with-handlers ([exn:break? void])
(copy-port cin in) (parameterize-break #t
(ready-for-break #f))) (ready-for-break #t)
(lambda () (close-output-port in))) (copy-port cin in)
(ready-for-break #t))) (ready-for-break #f))))
in)) (lambda () (close-output-port in)))
(ready-for-break #t))))
in))
(define (streamify-out cout out) (define (streamify-out cout out)
(if (and cout (if (and cout

View File

@ -195,7 +195,8 @@
(when it (when it
;; stop piping output to subprocess ;; stop piping output to subprocess
(semaphore-wait it-ready) (semaphore-wait it-ready)
(break-thread it)) (break-thread it)
(thread-wait it))
;; wait for other pipes to run dry: ;; wait for other pipes to run dry:
(when (thread? ot) (thread-wait ot)) (when (thread? ot) (thread-wait ot))
(when (thread? et) (thread-wait et)) (when (thread? et) (thread-wait et))