Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] thread_group::join_any
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2010-06-10 16:57:13

On 01/06/2010 18.15, vicente.botet wrote:
> The problem with your implementation is that use polling to joing a thread.
> I think that join_any could be implemented by adding a condition that will be notified by each one of the threads.
> Even if this could seam intrusive we can define thread_group class that creates the threads and wraps the call
> to the user function with the condition.

So what you propose is to encapsulate the original thead into a class
with the operator()() getting:

-) a reference to a condition from the thread_group (theCondition)
-) a reference to a mutex from the thread_group (theMutex)
-) a reference to the "threadfunction" being added (theOriginalFunction)

register as "threadfunction" this wrapper with the operator()()
implemented something like this:

TWrapper::operator()() {
   try {
     scoped_lock myGuard(theLock);
   catch(...) {

and then:

thread_group::join_any() {
   scoped_lock myGuard(theMutex);
   if (all threads are joinable) {
   } else {

I think it could work.

Gaetano Mendola

Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at