Boost logo

Threads-Devel :

From: Anthony Williams (anthony_at_[hidden])
Date: 2008-01-31 06:06:56


Quoting joop renes <jj.renes_at_[hidden]>:

>> From: Anthony Williams <anthony_at_[hidden]>
>> Quoting joop renes <jj.renes_at_[hidden]>:
>>
>> > in a hobby project i need to work with pointers to a family of
>> > polymorphic objects and i want to do multi-threaded computations with
>> > them. does boost have thread-safe smart pointers? i tried Loki but run
>> > into problems to find the correct policy classes fot the multi-threaded
>> > case
>> > any suggestions please?
>>
>> It depends what you're trying to do. You can safely pass shared_ptrs
>> around between threads, provided you don't update the same instance
>> from multiple threads at the same time, or update an instance from one
>> thread whilst reading it from another. It's quite OK to copy
>> shared_ptrs (even those that refer to the same object) in multiple
>> threads concurrently --- the reference count is thread safe.

> thanks for your speedy response.
> The computatations i do can be divided into a part where shared STL
> containers and the shared pointers are read only to compute an
> intermediate result, followed by an update part of a shared variable.

That usage description, and your sample code makes me think that
boost::shared_ptr is ideal for the job --- you're not changing the
shared_ptr itself, just reading and copying it, which is fine.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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