# # ThreadGroup provides a means of keeping track of a number of threads as a # group. # # A given Thread object can only belong to one ThreadGroup at a time; adding a # thread to a new group will remove it from any previous group. # # Newly created threads belong to the same group as the thread from which they # were created. # class ThreadGroup < Object # # Adds the given `thread` to this group, removing it from any other group to # which it may have previously been a member. # # puts "Initial group is #{ThreadGroup::Default.list}" # tg = ThreadGroup.new # t1 = Thread.new { sleep } # t2 = Thread.new { sleep } # puts "t1 is #{t1}" # puts "t2 is #{t2}" # tg.add(t1) # puts "Initial group now #{ThreadGroup::Default.list}" # puts "tg group now #{tg.list}" # # This will produce: # # Initial group is # # t1 is # # t2 is # # Initial group now ## # tg group now # # def add: (Thread thread) -> ThreadGroup # # Prevents threads from being added to or removed from the receiving # ThreadGroup. # # New threads can still be started in an enclosed ThreadGroup. # # ThreadGroup::Default.enclose #=> # # thr = Thread.new { Thread.stop } #=> # # tg = ThreadGroup.new #=> # # tg.add thr # #=> ThreadError: can't move from the enclosed thread group # def enclose: () -> self # # Returns `true` if the `thgrp` is enclosed. See also ThreadGroup#enclose. # def enclosed?: () -> bool # # Returns an array of all existing Thread objects that belong to this group. # # ThreadGroup::Default.list #=> [#] # def list: () -> ::Array[Thread] end # # The default ThreadGroup created when Ruby starts; all Threads belong to it by # default. # ThreadGroup::Default: ThreadGroup