[plt-scheme] thread shutting down its own custodian

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Sat May 22 10:15:05 EDT 2010

I don't know if it is a valid worry. But if it is, you could make
another thread that does this:

(thread (lambda () (let loop (custodian-shutdown-all (channel-get
kill-ch)) (loop))))

and have your original thread do (channel-put kill-ch
(current-custodian)) as its final action.

Jay

On Sat, May 22, 2010 at 8:11 AM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> Anyone who knows custodians and threads well have a minute to sanity-check
> this for me?
>
> In a conventional TCP server that has one request per connection and creates
> a thread for each request... I am currently establishing a new
> current-custodian for the block of code that calls "tcp-accept", and having
> the thread created within that block call "custodian-shutdown-all" on that
> custodian (as the thread's final act).  A simplified example:
>
>   (let loop ()
>     (let ((request-cust (make-custodian my-listener-cust)))
>       (parameterize ((current-custodian request-cust))
>         (let-values (((in out) (tcp-accept my-listener)))
>           (thread (lambda ()
>                     (dynamic-wind
>                       (lambda () #f)
>                       (lambda ()
>                         (my-handle-request in out))
>                       (lambda ()
>                         (custodian-shutdown-all request-cust)))))))
>       (loop)))
>
> This seems to work, but I'm wondering whether there's a race condition
> (e.g., custodian shutdown code is executed in the thread itself, and that
> code can kill its own evaluation prematurely), and whether there's a better
> way to do it.
>
> --
> http://www.neilvandyke.org/
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.