chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Threads and dynamic-wind still problematic


From: Tobia Conforto
Subject: Re: [Chicken-users] Threads and dynamic-wind still problematic
Date: Sun, 8 Mar 2009 23:21:21 +0100

Peter Bex wrote:
Yup, thanks for asking him.  It still sucks, though ;)

This is yet another solution, in case you can't (or don't want to) steal the exception handler from the primordial thread. This one may be safer. But then again, I'm probably missing Marc Feeley's point completely, so it might not be safe to use at all :-)

#;1> (use srfi-18)
; loading library srfi-18 ...
#;2> (define (exception-protect thunk)
--->   (define exn-message (condition-property-accessor 'exn 'message))
--->   (lambda ()
--->     (call-with-current-continuation
--->       (lambda (quit)
--->         (with-exception-handler
--->           (lambda (exn)
--->             (print "Error: " (exn-message exn))
--->             (quit))
--->           thunk)))))
#;3> (define (test)
--->   (dynamic-wind
--->     (lambda ()
--->       (print "BEFORE"))
--->     (lambda ()
--->       (error "die!")
--->       (print "OH NOES"))
--->     (lambda ()
--->       (print "AFTER"))))
#;4> (thread-join! (thread-start! (exception-protect test)))
BEFORE
Error: die!
AFTER
#;5>

Tobia




reply via email to

[Prev in Thread] Current Thread [Next in Thread]