(declare (usual-integrations))
\f
-(define (carefully procedure if-overflow if-timeout)
- (let ((thread #f)
- (mutex (make-thread-mutex))
- (condvar (make-condition-variable))
- (gc-env (->environment '(runtime garbage-collector))))
- (define (start-it)
- (with-thread-mutex-lock mutex
- (lambda ()
- (do () (thread)
- (condition-variable-wait! condvar mutex))))
- (let ((default/stack-overflow (access default/stack-overflow gc-env)))
- (define (give-up)
- (if (eq? thread (current-thread))
- (exit-current-thread (if-overflow))
- (default/stack-overflow)))
- (call-with-current-continuation
- (lambda (abort)
- (fluid-let (((access hook/stack-overflow gc-env)
- (lambda () (within-continuation abort give-up))))
- (exit-current-thread (procedure)))))))
- (define (stop-it)
- (assert thread)
- (signal-thread-event thread
- (lambda ()
- (exit-current-thread (if-timeout)))))
- (let ((t (create-thread #f start-it)))
- (with-thread-mutex-lock mutex
- (lambda ()
- (set! thread t)
- (condition-variable-broadcast! condvar))))
- (let ((result #f))
- (define (done-it thread* value)
- (assert (eq? thread* thread))
- (set! result value))
- (join-thread thread done-it)
- (let ((timer))
- (dynamic-wind
- (lambda () (set! timer (register-timer-event 1000 stop-it)))
- (lambda () (do () (result) (suspend-current-thread)))
- (lambda () (deregister-timer-event (set! timer))))))))
-
(define (words-in-stack)
(let ((status (gc-space-status)))
(let ((bytes-per-word (vector-ref status 0))
(define assert-string
(predicate-assertion string? "string"))
-(define (carefully procedure if-overflow if-timeout)
- (let ((thread #f)
- (mutex (make-thread-mutex))
- (condvar (make-condition-variable))
- (gc-env (->environment '(runtime garbage-collector))))
- (define (start-it)
- (with-thread-mutex-lock mutex
- (lambda ()
- (do () (thread)
- (condition-variable-wait! condvar mutex))))
- (let ((default/stack-overflow (access default/stack-overflow gc-env)))
- (define (give-up)
- (if (eq? thread (current-thread))
- (exit-current-thread (if-overflow))
- (default/stack-overflow)))
- (call-with-current-continuation
- (lambda (abort)
- (fluid-let (((access hook/stack-overflow gc-env)
- (lambda () (within-continuation abort give-up))))
- (exit-current-thread (procedure)))))))
- (define (stop-it)
- (assert thread)
- (signal-thread-event thread
- (lambda ()
- (exit-current-thread (if-timeout)))))
- (let ((t (create-thread #f start-it)))
- (with-thread-mutex-lock mutex
- (lambda ()
- (set! thread t)
- (condition-variable-broadcast! condvar))))
- (let ((result #f))
- (define (done-it thread* value)
- (assert (eq? thread* thread))
- (set! result value))
- (join-thread thread done-it)
- (let ((timer))
- (dynamic-wind
- (lambda () (set! timer (register-timer-event 1000 stop-it)))
- (lambda () (do () (result) (suspend-current-thread)))
- (lambda () (deregister-timer-event (set! timer))))))))
-
(define-test 'circular/simple
(lambda ()
(define (doit)
(declare (usual-integrations))
\f
-(define (carefully procedure if-overflow if-timeout)
- (let ((thread #f)
- (mutex (make-thread-mutex))
- (condvar (make-condition-variable))
- (gc-env (->environment '(runtime garbage-collector))))
- (define (start-it)
- (with-thread-mutex-lock mutex
- (lambda ()
- (do () (thread)
- (condition-variable-wait! condvar mutex))))
- (let ((default/stack-overflow (access default/stack-overflow gc-env)))
- (define (give-up)
- (if (eq? thread (current-thread))
- (exit-current-thread (if-overflow))
- (default/stack-overflow)))
- (call-with-current-continuation
- (lambda (abort)
- (fluid-let (((access hook/stack-overflow gc-env)
- (lambda () (within-continuation abort give-up))))
- (exit-current-thread (procedure)))))))
- (define (stop-it)
- (assert thread)
- (signal-thread-event thread
- (lambda ()
- (exit-current-thread (if-timeout)))))
- (let ((t (create-thread #f start-it)))
- (with-thread-mutex-lock mutex
- (lambda ()
- (set! thread t)
- (condition-variable-broadcast! condvar))))
- (let ((result #f))
- (define (done-it thread* value)
- (assert (eq? thread* thread))
- (set! result value))
- (join-thread thread done-it)
- (let ((timer))
- (dynamic-wind
- (lambda () (set! timer (register-timer-event 1000 stop-it)))
- (lambda () (do () (result) (suspend-current-thread)))
- (lambda () (deregister-timer-event (set! timer))))))))
-
(define-test 'delay-force-loop
(lambda ()
(assert-error
(list "an object" (if- "not") "matching" (marker))))
(define-for-tests assert-matches (match-assertion #f))
-(define-for-tests assert-!matches (match-assertion #t))
\ No newline at end of file
+(define-for-tests assert-!matches (match-assertion #t))
+\f
+(define-for-tests (carefully procedure if-overflow if-timeout)
+ (let ((gc-env (->environment '(runtime garbage-collector))))
+ (define (start-it)
+ (let ((default/stack-overflow (access default/stack-overflow gc-env))
+ (thread (current-thread)))
+ (define (give-up)
+ (if (eq? thread (current-thread))
+ (exit-current-thread (if-overflow))
+ (default/stack-overflow)))
+ (call-with-current-continuation
+ (lambda (abort)
+ (fluid-let (((access hook/stack-overflow gc-env)
+ (lambda () (within-continuation abort give-up))))
+ (exit-current-thread (procedure)))))))
+ (let ((thread (create-thread #f start-it)))
+ (define (stop-it)
+ (signal-thread-event thread
+ (lambda ()
+ (exit-current-thread (if-timeout)))))
+ (let ((result #f))
+ (define (done-it thread* value)
+ (assert (eq? thread* thread))
+ (set! result value))
+ (join-thread thread done-it)
+ (let ((timer))
+ (dynamic-wind
+ (lambda () (set! timer (register-timer-event 1000 stop-it)))
+ (lambda () (do () (result) (suspend-current-thread)))
+ (lambda () (deregister-timer-event (set! timer)))))))))
\ No newline at end of file