views:

73

answers:

3

If you have to pass objects across threads which smart pointer type is best to use?

Assuming the object being passed is thread safe.

+5  A: 

A shared_ptr would work for sharing data. Its counter is atomic, so you won't run into problems there, and when the last thread is done it goes away.

GMan
+1  A: 

shared_ptr for shared ownership.

unique_ptr to transfer ownership from thread to thread

Steve Townsend
A: 

Just a little hint:
There are also really good examples about what you can and what you can't do with shared_ptr in a thread safe manner: shared_ptr - thread safety
Just in case you want to do a bit more that just transfer the ownership

Daniel