Simplify and extend using the knots exception with stack

This commit is contained in:
Christopher Baines 2025-02-27 12:08:41 +00:00
parent d8bc09755e
commit ed4113af51
3 changed files with 38 additions and 29 deletions

View file

@ -52,7 +52,11 @@
(let ((stack (make-stack #t
0 prompt-tag
0 (and prompt-tag 1))))
(put-message reply (list 'exception exn stack)))))
(put-message reply
(list 'exception
(make-exception
exn
(make-knots-exception stack)))))))
(return))
(lambda ()
(call-with-values
@ -69,12 +73,7 @@
(map
(match-lambda
(('exception exn stack)
(let ((knots-exn
(make-knots-exception stack)))
(raise-exception
(make-exception
knots-exn
exn))))
(raise-exception exn))
(result
(apply values result)))
responses)))
@ -118,13 +117,8 @@
(vector-ref result-vec index))
(lambda (result)
(match result
(('exception exn stack)
(let ((knots-exn
(make-knots-exception stack)))
(raise-exception
(make-exception
knots-exn
exn))))
(('exception exn)
(raise-exception exn))
(_
(vector-set! result-vec
index
@ -275,10 +269,5 @@
(put-message input-channel (cons reply-channel args))
(match (get-message reply-channel)
(('result . vals) (apply values vals))
(('exception exn stack)
(let ((knots-exn
(make-knots-exception stack)))
(raise-exception
(make-exception
knots-exn
exn))))))))
(('exception exn)
(raise-exception exn))))))

View file

@ -253,18 +253,20 @@ arguments of the thread pool procedure."
proc)
(with-exception-handler
(lambda (exn)
(when (log-exception? exn)
(simple-format
(current-error-port)
"thread-pool: exception running ~A\n" proc)
(print-backtrace-and-exception/knots
exn))
(raise-exception exn))
(match (fluid-ref %stacks)
((stack-tag . prompt-tag)
(let ((stack (make-stack #t
0 prompt-tag
0 (and prompt-tag 1))))
(raise-exception
(make-exception
exn
(make-knots-exception stack)))))))
(lambda ()
(call-with-values
(lambda ()
(start-stack
'thread-pool
#t
(apply proc args)))
(lambda vals
(cons (/ (- (get-internal-real-time)

View file

@ -2,6 +2,7 @@
(srfi srfi-71)
(fibers)
(unit-test)
(knots)
(knots thread-pool))
(let ((thread-pool
@ -41,4 +42,21 @@
(process-job 3))
(let ((thread-pool
(make-thread-pool 2)))
(run-fibers-for-tests
(lambda ()
(assert-equal
#t
(with-exception-handler
(lambda (exn)
(knots-exception? exn))
(lambda ()
(call-with-thread
thread-pool
(lambda ()
(+ 1 'a))))
#:unwind? #t)))))
(display "thread-pool test finished successfully\n")