Hi, I just got bitten by this problem: http://lists.gnu.org/archive/html/chicken-users/2008-04/msg00023.html
I'm increasing and decreasing a mutex value based on how many threads are doing some work. When they stop working, the mutex is decreased and when they start, the mutex is increased. I decided to wrap the thunk that does the work in a dynamic-wind to protect it from escape continuations being called, and from exceptions. However, it turns out that an exception thrown in a thread simply terminates the thread instead of unwinding the stack. The same does not happen in the primordial thread: $ csi #;1> (use srfi-18) ; loading library srfi-18 ... #;2> (dynamic-wind (lambda () (print "BEFORE")) (lambda () (error "die!")) (lambda () (print "AFTER"))) BEFORE Error: die! Call history: <syntax> (begin (error "die!")) <syntax> (error "die!") <syntax> (lambda () (print "AFTER")) <syntax> (begin (print "AFTER")) <syntax> (print "AFTER") <eval> (dynamic-wind (lambda () (print "BEFORE")) (lambda () (error "die!")) (lambda () (print "AFTER"))) <eval> (print "BEFORE") <eval> (error "die!") <-- AFTER #;2> (thread-start! (lambda () (dynamic-wind (lambda () (print "BEFORE")) (lambda () (error "die!")) (lambda () (print "AFTER"))))) #<thread: thread0> #;3> BEFORE Warning (#<thread: thread0>): : die! Call history: <eval> (dynamic-wind (lambda () (print "BEFORE")) (lambda () (error "die!")) (lambda () (print "AFTER"))) <eval> (print "BEFORE") <eval> (error "die!") <-- I'd say this is *extremely* counterintuitive; that raising an error outside a thread (or rather; in the primordial thread) causes pending dynamic-unwinds to unwind while doing the same in a thread does not. In fact, I'd say it's outright dangerous; this can cause hard to track race condition type bugs. This bug is still there in Chicken 4. Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth
pgp2k4Zow7nSv.pgp
Description: PGP signature
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users