Skip to content

Commit

Permalink
Some refactoring:
Browse files Browse the repository at this point in the history
1. we don't need to get the thread of the eventspace anymore because
we're waiting for installer-cust to terminate now, so we can move the
thread that is watching outside of the callback in the new eventspace

2. this code now accesses completed-successfully? only from one
thread. I don't think it was an actual race condition in the previous
version because of the timing of the killing of the custodian but this
version of the code seems easier to reason about
  • Loading branch information
rfindler committed Dec 5, 2022
1 parent 5b58fcd commit ba3b19b
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions gui-lib/mrlib/terminal.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -202,34 +202,32 @@

(define output-port (mk-port plain-style))
(define error-port (mk-port error-style))


;; accessed and mutated only on the handler thread of `orig-eventspace`
(define completed-successfully? #f)

(define installer-cust (make-custodian))

(thread
(lambda ()
(sync (make-custodian-box installer-cust #t))
(parameterize ([current-eventspace inst-eventspace])
(queue-callback
(λ ()
(send kill-button enable #f)
(when close-button (send close-button enable #t))
(set! currently-can-close? #t)
(semaphore-post can-close-sema))))
(parameterize ([current-eventspace orig-eventspace])
(queue-callback
(lambda ()
(unless completed-successfully?
(cleanup-thunk)))))))

(parameterize ([current-custodian installer-cust])
(parameterize ([current-eventspace (make-eventspace)])
(queue-callback
(lambda ()

(let ([installer-thread (current-thread)])
(parameterize ([current-custodian orig-custodian])
(thread
(lambda ()
(sync (make-custodian-box installer-cust #t))
(parameterize ([current-eventspace inst-eventspace])
(queue-callback
(λ ()
(send kill-button enable #f)
(when close-button (send close-button enable #t))
(set! currently-can-close? #t)
(semaphore-post can-close-sema))))
(unless completed-successfully?
(parameterize ([current-eventspace orig-eventspace])
(queue-callback
(lambda ()
(cleanup-thunk)))))))))

(let/ec k
(parameterize ([current-output-port output-port]
[current-error-port error-port]
Expand Down

0 comments on commit ba3b19b

Please sign in to comment.