I'm running a thread with memory limit using custodian-limit-memory.
How do I reliably detect whether the thread I'm running was terminated
normally or aborted by custodian shutdown? Plus, is it possible to
obtain the context at the time the memory limit was exceeded?

I can think these two:

1. Use a channel to indicate normal termination, or
2. detect whether the custodian had been shut down.

Both methods address the first question but not the second question.
Any pointers?


    (define TIMEOUT 60)
    (define MEMORY-LIMIT (* 2 1024 1024 1024))

    (parameterize ([current-custodian (make-custodian)])
      (custodian-limit-memory (current-custodian) MEMORY-LIMIT)
      (define thread-id
        (thread (λ ()
                  (displayln "This displayln probably takes lots of memory"))))
      (define ended? (sync/timeout/enable-break TIMEOUT thread-id))
      (unless ended? (break-thread thread-id 'terminate))
      (thread-wait thread-id)
      (when (custodian-shut-down? (current-custodian))
        ;; The context here is not the right one and the exception is not
        ;; raised in the right thread
        (raise (exn:fail:out-of-memory "Out of memory"

You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to