vicente.botet | 10 May 13:33
Picon

[thread] thread_group create_thread template function

Hi,

the thread_group::create_thread takes a const function0<void> parameter:
    thread* create_thread(const function0<void>& threadfunc);

The function0 implies already a memory allocation. The templated version 
look like:

    template <class Threadable>
    thread* thread_group::create_thread(Threadable threadfunc)
    {
        // No scoped_lock required here since the only "shared data" that's
        // modified here occurs inside add_thread which does scoped_lock.
        std::auto_ptr<thread> thrd(new thread(threadfunc));
        add_thread(thrd.get());
        return thrd.release();
    }

Which works faster because no need to allocate memory for the 
boost::function0<void()>.

Anthony, if there is nothing wrong, could this substitute the create_thread 
function in next Boost::thread release?

Best regards
_____________________
Vicente Juan Botet Escriba 

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
(Continue reading)

Anthony Williams | 12 May 12:54
Picon
Favicon

Re: [thread] thread_group create_thread template function

"vicente.botet" <vicente.botet <at> wanadoo.fr> writes:

> the thread_group::create_thread takes a const function0<void> parameter:
>     thread* create_thread(const function0<void>& threadfunc);
>
> The function0 implies already a memory allocation. The templated version 
> look like:
>
>     template <class Threadable>
>     thread* thread_group::create_thread(Threadable threadfunc)
>     {
>         // No scoped_lock required here since the only "shared data" that's
>         // modified here occurs inside add_thread which does scoped_lock.
>         std::auto_ptr<thread> thrd(new thread(threadfunc));
>         add_thread(thrd.get());
>         return thrd.release();
>     }
>
> Which works faster because no need to allocate memory for the 
> boost::function0<void()>.
>
> Anthony, if there is nothing wrong, could this substitute the create_thread 
> function in next Boost::thread release?

That's a reasonable idea. I'll look at it when I revise thread_group.

Anthony
--

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
(Continue reading)

vicente.botet | 12 May 13:16
Picon

Re: [thread] thread_group create_thread template function

----- Original Message ----- 
From: "Anthony Williams" <anthony_w.geo <at> yahoo.com>
To: <boost <at> lists.boost.org>
Sent: Monday, May 12, 2008 12:54 PM
Subject: Re: [boost] [thread] thread_group create_thread template function

> "vicente.botet" <vicente.botet <at> wanadoo.fr> writes:
>
>> the thread_group::create_thread takes a const function0<void> parameter:
>>     thread* create_thread(const function0<void>& threadfunc);
>>
>> The function0 implies already a memory allocation. The templated version
>> look like:
>>
>>     template <class Threadable>
>>     thread* thread_group::create_thread(Threadable threadfunc)
>>     {
>>         // No scoped_lock required here since the only "shared data" 
>> that's
>>         // modified here occurs inside add_thread which does scoped_lock.
>>         std::auto_ptr<thread> thrd(new thread(threadfunc));
>>         add_thread(thrd.get());
>>         return thrd.release();
>>     }
>>
>> Which works faster because no need to allocate memory for the
>> boost::function0<void()>.
>>
>> Anthony, if there is nothing wrong, could this substitute the 
>> create_thread
(Continue reading)


Gmane