I was flicking through the Pickaxe, looking for the documentation on Thread
, and came across ThreadGroup
.
The documentation describes what it does, but it doesn't explain what it's for.
Is a thread group related to a thread pool, which I assumed Ruby doesn't have?
New threads are created in their parent's ThreadGroup. You can use the ThreadGroup to organize the implicit tree structure given by the parent threads spawning other threads, and use the list
instance method to get all threads which have not terminated yet, i.e. to define methods operating on all threads in the group.
Additionaly, you can use enclose
to prohibit adding (or removing) threads to this group, if you run untrusted code and want to keep an eye on the threads it spawns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With