make an eventspace thread survive a break exception

When an eventspace is created, its thread implicitly calls
`yield'. It now effectively loops with `yield' and while
catching continuation aborts.

Closes PR 12566
This commit is contained in:
Matthew Flatt 2012-02-13 16:16:23 -07:00
parent aee0868f24
commit 967372c23d
2 changed files with 43 additions and 11 deletions

View File

@ -383,17 +383,30 @@
(define make-new-eventspace
(let ([make-eventspace
(lambda ()
(letrec ([pause (make-semaphore)]
[es
(define pause (make-semaphore))
(define break-paramz (current-break-parameterization))
(define es
(make-eventspace*
(parameterize-break
#f ; disable breaks until we're in the yield loop
(thread
(lambda ()
(sync pause)
(sync pause) ; wait until `es' has a value
(thread-cell-set! handler-thread-of es)
(current-eventspace es)
(yield (make-semaphore)))))])
(semaphore-post pause)
es))])
(let loop ()
(call-with-continuation-prompt
(lambda ()
;; re-enable breaks (if they are supposed to be enabled):
(call-with-break-parameterization
break-paramz
(lambda ()
;; yield; any abort (including a break exception)
;; will get caught and the loop will yield again
(yield (make-semaphore))))))
(loop)))))))
(semaphore-post pause) ; `es' has a value
es)])
make-eventspace))
(define (queue-event eventspace thunk [level 'med])

View File

@ -105,4 +105,23 @@
(try-use-es (lambda () (queue-callback void)))
(try-use-es (lambda () (send tmr start 100 #t)))
;; ----------------------------------------
;; Check that breaking an eventspace thread doesn't kill it:
(let ()
(define evtsp (make-eventspace))
(define evtth (eventspace-handler-thread evtsp))
(sleep 0.1)
(break-thread evtth)
(define done (make-semaphore))
(parameterize ((current-eventspace evtsp))
(queue-callback (lambda () (semaphore-post done))))
(unless (sync/timeout 3 done)
(error "broken thread is really broken")))
;; ----------------------------------------
(report-errs)