Boost logo

Boost Users :

From: Tristan King (tristanking_at_[hidden])
Date: 2004-06-12 20:22:59


Rene Rivera wrote:

> Ben Hutchings wrote:
>
>> Tristan King <tristanking_at_[hidden]> wrote:
>>
>>> Hi,
>>> I'm having trouble getting shared_ptr objects and threads to work in
>>> harmony.
>>
> [snip]
>
>>> can anyone give me any pointers on how to get around this problem?
>>
>>
>> <snip>
>>
>> I suggest you create your thread objects with 'new' instead, or
>> else define an array of them outside the loop.
>
>
> Or just don't use boost:ref, and have the thread function objects copied.
>
>

Rene, is that possible with a stuct?
the problem is that i need give the thread some initial parameters, and
i'm not sure if thats possible using a simple function.

Ben's solution worked, however is probably not the best solution. as the
number of threads called needs to be infinate (within physical limits of
course).

if a thread is created using new
    simple_thread* trd = new simple_thread( p );
and started using:
    threads.create_thread( boost::ref( *trd ) );
trd still needs to be destroyed using "delete" somewhere right?
or will the memory be free'd when the thread finishes execution?

is there anyway to check if a thread has ended and thus free the memory?
otherwise using new generates too many memory allocations without
reasonable memory deletions. and the program would soon run out of
memory (unless i'm missing something here)

thanks again
--Tristan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net