Boost logo

Threads-Devel :

Subject: [Threads-devel] thread_group::join_any
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2010-05-31 11:05:18


Hi all,
in my application I found myself to use the following pattern:

1) create a group of thread
2) add some threads to this group
3) wait until one of the threads in this group completed then
   interrupt/join all.

To do this I wrote my own class ThreadGroup with the method
join_any doing exactly the operation at the point 3.

May be would be usefull, for other thread_group users have such
functionality as well.

The method should sound like this (I didn't try it):

        void join_any()
        {
            boost::shared_lock<shared_mutex> guard(m);
            bool one_join_success = false;

            while(!one_join_success) {
              for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
                  it!=end;
                  ++it)
              {
                one_join_success = (*it)->timed_join(boost::posix_time::millisec(10));
                if (one_join_success) {
                  interrupt_all();
                  break;
                }
              }
           }
           join_all();
        }

if you think is worth to have it I can provide a patch.

Regards
Gaetano Mendola


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk