- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hiya,
We rely a lot on the Boost library, specifically the shared_ptr<> class.
Has anyone used shared pointers successfully with multiple threads and Intel TBB? I'm unsure whether shared pointers are thread-safe...
Any advice appreciated!
Cheers.
We rely a lot on the Boost library, specifically the shared_ptr<> class.
Has anyone used shared pointers successfully with multiple threads and Intel TBB? I'm unsure whether shared pointers are thread-safe...
Any advice appreciated!
Cheers.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As long as you are aware of the limitations to the thread-safe use of shared_ptr instances, you'll be able to use them with TBB.
(Added) Also be aware that the administrative cost of managing those reference counts can easily outweigh savings in memory allocation, so be careful to consider when to share objects and when to just copy them.
(Added) Also be aware that the administrative cost of managing those reference counts can easily outweigh savings in memory allocation, so be careful to consider when to share objects and when to just copy them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting beebs1
...I'm unsure whether shared pointers are thread-safe...
What doesthe Boost documentation say about it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"What doesthe Boost documentation say about it?"
Please click on the link provided in #1.
Regarding the cost of managing reference counts, it would probably even be a good idea to pass shared_ptr instances by const reference instead of by value, although I would prefer to see someone else's anecdotal evidence for that (time program with lots of pass-by-value, correct it, time again, compare), or a reference to somebody else's study about this. :-)
Please click on the link provided in #1.
Regarding the cost of managing reference counts, it would probably even be a good idea to pass shared_ptr instances by const reference instead of by value, although I would prefer to see someone else's anecdotal evidence for that (time program with lots of pass-by-value, correct it, time again, compare), or a reference to somebody else's study about this. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Raf Schietekat
"What doesthe Boost documentation say about it?"
Please click on the link provided in #1.
...
Please click on the link provided in #1.
...
Itsays:
...
shared_ptr objects offer the same level of thread safety as built-in types. A shared_ptr instance can be "read" (accessed using only const operations) simultaneously by multiple threads. Different shared_ptr instances can be "written to" (accessed using mutable operations such as operator= or reset) simultaneosly by multiple threads (even when these instances are copies, and share the same reference count underneath.)
...
Thank you.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page