<br><div class="gmail_quote">On Tue, Apr 21, 2009 at 3:42 AM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">> what happens when a thread is killed in the middle of executing a<br>
> dynamic-wind block? Does the post-thunk get executed still?<br>
<br>
</div>No, it doesn't.<br>
<div class="im"></div></blockquote><div><br>Thanks for the verification. <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
</div>In general, one might have to rewrite the program to make it<br>
kill-safe. That is, there is no way to just take code that<br>
synchronizes in some arbitrary way and make it kill-safe. Perhaps if<br>
you can say more about what the actual syncronization protocol is, we<br>
can help you make it kill-safe.</blockquote><div><br>I try to verify the possibility first to ensure my bug report is not bogus :) <br><br>The blocked code exists in planet package schematics spgsql.plt, in private/p3.ss & private/connection.ss. Inside - it uses a semaphore to lock the critical region. The function protocol3:new-exchange waits for the semaphore, and protocol3:end-exchange releases the semaphore. <br>
<br>protocol3:end-exchange appears to be only called by base%:end-exchange in private/connection.ss, which appears to be only called in primitive-query-mixin:with-final-end-exchange, which generates a dynamic-wind block that calls the end-exchange in post-thunk.<br>
<br><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span>My threads eventually block on protocol3:new-exchange, which appears to be waiting for a semaphore that's never released (and if dynamic-wind is not kill-safe that it can explain the behavior).<br>
<br>This behavior is intermittent and hard to reproduce, but definitely there (as once it happens my app does nothing). Without Matthew's stack tracing approach I could not find out where it was blocking and how. <br>
<br>Below is the code snippet from the two files. <br><br>;; private/p3.ss <br>;; protocol3:new-exchange : protocol3 -> stream<br>(define (protocol3:new-exchange protocol)<br> (semaphore-wait (protocol3-ownerlock protocol))<br>
...)<br>;; protocol3:end-exchange : protocol3 -> void<br>(define (protocol3:end-exchange protocol)<br> (semaphore-post (protocol3-ownerlock protocol)))<br><br>;; private/connection.ss<br>;; base%<br>(define base%<br>
(class* object% (base<%>)<br> ...<br> ;; new-exchange : -> stream<br> (define/public-final (new-exchange)<br> (unless protocol<br> (raise-user-error 'connection<%> "not connected"))<br>
(protocol3:new-exchange protocol))<br> <br> ;; end-exchange : -> void<br> (define/public-final (end-exchange)<br> (unless protocol<br> (raise-user-error 'connection<%> "not connected"))<br>
(protocol3:end-exchange protocol))<br> ...))<br>(define primitive-query-mixin<br> (mixin (base<%>) (primitive-query<%>)<br> ... <br> (define-syntax with-final-end-exchange<br> (syntax-rules ()<br>
[(with-final-end-exchange . b)<br> (dynamic-wind<br> void<br> (lambda () . b)<br> (lambda () (end-exchange)))]))<br> ...))<br><br></div></div>