Skip to content

Commit ba3b19b

Browse files
committed
Some refactoring:
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
1 parent 5b58fcd commit ba3b19b

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

gui-lib/mrlib/terminal.rkt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,34 +202,32 @@
202202

203203
(define output-port (mk-port plain-style))
204204
(define error-port (mk-port error-style))
205-
205+
206+
;; accessed and mutated only on the handler thread of `orig-eventspace`
206207
(define completed-successfully? #f)
207208

208209
(define installer-cust (make-custodian))
209-
210+
(thread
211+
(lambda ()
212+
(sync (make-custodian-box installer-cust #t))
213+
(parameterize ([current-eventspace inst-eventspace])
214+
(queue-callback
215+
(λ ()
216+
(send kill-button enable #f)
217+
(when close-button (send close-button enable #t))
218+
(set! currently-can-close? #t)
219+
(semaphore-post can-close-sema))))
220+
(parameterize ([current-eventspace orig-eventspace])
221+
(queue-callback
222+
(lambda ()
223+
(unless completed-successfully?
224+
(cleanup-thunk)))))))
225+
210226
(parameterize ([current-custodian installer-cust])
211227
(parameterize ([current-eventspace (make-eventspace)])
212228
(queue-callback
213229
(lambda ()
214230

215-
(let ([installer-thread (current-thread)])
216-
(parameterize ([current-custodian orig-custodian])
217-
(thread
218-
(lambda ()
219-
(sync (make-custodian-box installer-cust #t))
220-
(parameterize ([current-eventspace inst-eventspace])
221-
(queue-callback
222-
(λ ()
223-
(send kill-button enable #f)
224-
(when close-button (send close-button enable #t))
225-
(set! currently-can-close? #t)
226-
(semaphore-post can-close-sema))))
227-
(unless completed-successfully?
228-
(parameterize ([current-eventspace orig-eventspace])
229-
(queue-callback
230-
(lambda ()
231-
(cleanup-thunk)))))))))
232-
233231
(let/ec k
234232
(parameterize ([current-output-port output-port]
235233
[current-error-port error-port]

0 commit comments

Comments
 (0)