开发者

What is Ruby's ThreadGroup for?

I was flicking through the Pickaxe, looking for the documentation on Thread, a开发者_如何转开发nd 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜