Custodians
A custodian manages a collection of threads, file-stream ports, TCP ports, TCP listeners, UDP sockets, and byte converters.
Whenever a thread, etc. is created, it is placed under the management of the current custodian as determined by the current-custodian
parameter.
Except for the root custodian, every custodian itself it managed by a custodian, so that custodians form a hierarchy. Every
object managed by a subordinate custodian is also managed by the custodian's owner.
When a custodian is shut down via custodian-shutdown-all, it forcibly and immediately closes the ports, TCP connections, etc.
that it manages, as well as terminating (or suspending) its threads. A custodian that has been shut down cannot manage new objects.
If the current custodian is shut down before a procedure is called to create a managed resource (e.g., open-input-port, thread),
the exn:fail:contract exception is raised.
A thread can have multiple managing custodians, and a suspended thread created with thread/suspend-to-kill can have zero custodians.
Extra custodians become associated with a thread through thread-resume. When a thread has multiple custodians, it is not necessarily
killed by a custodian-shutdown-all, but shut-down custodians are removed from the thread's managing set, and the thread is killed
when its managing set becomes empty.
The values managed by a custodian are only weakly held by the custodian. As a result, a will can be executed for a value that
is managed by a custodian. In addition, a custodian only weakly references its subordinate custodians; if a subordinate custodian is
unreferenced but has its own subordinates, then the custodian may be collected, at which point its subordinates become immediately
subordinate to the collected custodian's superordinate custodian.
In addition to the other entities managed by a custodian, a custodian box created with make-custodian-box strongly holds onto a value
placed in the box until the box's custodian is shut down. The custodian only weakly retains the box itself, however (so the box and
its content can be collected if there are no other references to them).
July 14th Tuesday (七月 十四日 火曜日)
最新推荐文章于 2021-12-18 14:48:30 发布