From: Alex Young Date: 2012-02-27T01:48:34+09:00 Subject: [ruby-core:42955] Re: [ruby-trunk - Feature #5958] ThreadGroup#join On 26/02/2012 08:32, Masaki Matsushita wrote: > > Issue #5958 has been updated by Masaki Matsushita. > > > Koichi Sasada wrote: >> What should happen when at least one thread causes an exception? > > Under the patch, joining thread also causes the exception if the thread is being joined. > Otherwise, nothing will happen on joining thread. > It behaves the same as thgrp.list.each(&:join). > > I think ThreadGroup#join may be more useful if it catches exceptions from all its threads and handles them like the following. > > thgrp.join do |th| # each thread which causes an exception > # handle an exception > end It'd be much less surprising to go through the normal rescue mechanism if possible. How about something like this: module ThreadGroupExceptions attr_accessor :next_in_group def each current = self while current yield current current = current.next_in_group end end end class ThreadGroup def join group_exc = nil list.each do |thread| begin thread.join rescue => exc exc.extend ThreadGroupExceptions group_exc, exc.next_in_group = exc, group_exc end end raise grp_exc if grp_exc end end It's slightly messy in that if you're not expecting there to be a ThreadGroup involved then you won't be aware of the mixin, but if you are, then everything's available as a linked list (which an Enumerable could be layered on, if needed), and you can just `rescue ThreadGroupExceptions` in that case. -- Alex