Tony The Lion
Tony The Lion

Reputation: 63250

Boost Smart Pointers and threading

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

Assuming the object being passed is thread safe.

Upvotes: 0

Views: 1032

Answers (3)

Daniel
Daniel

Reputation: 3063

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

Upvotes: 0

Steve Townsend
Steve Townsend

Reputation: 54168

shared_ptr for shared ownership.

unique_ptr to transfer ownership from thread to thread

Upvotes: 1

GManNickG
GManNickG

Reputation: 504053

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.

Upvotes: 5

Related Questions