[plt-scheme] thread shutting down its own custodian

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Sat May 22 10:19:20 EDT 2010

Thanks, Jay.  I think that's exactly what I'll do, unless I become 
confident that the current way is safe.

Jay McCarthy wrote at 05/22/2010 10:15 AM:
> 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
>>
>>     
>
>
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100522/e68db3e9/attachment.html>

Posted on the users mailing list.