|
Threads-Devel : |
Subject: Re: [Threads-devel] thread_group::join_any
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2010-07-18 06:24:33
On 11/06/2010 00:26, vicente.botet wrote:
> ----- Original Message -----
> From: "Gaetano Mendola"<mendola_at_[hidden]>
> To:<threads-devel_at_[hidden]>
> Sent: Thursday, June 10, 2010 10:57 PM
> Subject: Re: [Threads-devel] thread_group::join_any
>
>
>>
>> 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:
>>
> <snip>
>
>> I think it could work.
>
> Yes, someting like that.
Unfortunately that is not easy due the presence of this:
void thread_group::add_thread(thread* thrd);
in that case the thread being added is already running and there is no
way to wrap it. I think the class thread should be able to notify a
"subscriber" to it when it completes the running. In this way we can
have the thread_group subscribing to each thread being added and then
terminate all in case one of those notify the termination.
Gaetano Mendola