Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Ruby's ThreadGroup for?

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?

like image 880
Andrew Grimm Avatar asked May 10 '11 02:05

Andrew Grimm


1 Answers

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.

like image 121
dhoelzgen Avatar answered Oct 04 '22 20:10

dhoelzgen