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:04:58 +0100

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

It does. This is one way to solve it:

#;1> (use srfi-18)
; loading library srfi-18 ...
#;2> (define exception-protect
--->   (let ((original-exception-handler (current-exception-handler)))
--->     (lambda (thunk)
--->       (lambda ()
---> (with-exception-handler original-exception-handler thunk)))))
#;3> (define (test)
--->   (dynamic-wind
--->     (lambda ()
--->       (print "BEFORE"))
--->     (lambda ()
--->       (error "die!")
--->       (print "NOT PRINTING"))
--->     (lambda ()
--->       (print "AFTER"))))
#;4> (thread-join! (thread-start! (exception-protect test)))
BEFORE
Error: die!

        Call history:
        .
        .
        .
AFTER
#;4>

The key is defining exception-protect in the primordial thread. Then you can use it wherever you need it.

I'm not knowledgeable enough to wager what kinds of problems it may cause... and I have a feeling it may cause lots! Or maybe not. So use it at your own risk.

-Tobia




reply via email to

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