Are smart pointers threadsafe?

AJ
Total Points:
3,752
Status Points:
3,252
Brown Belt
May 5, 2008 9:15 AM PDT
Rate
 
#4 Reply to #3
I have used boost::shared_ptr in TBB applications before and it seemed to work just fine.  I believe there are atomic increment and decrement operations within it.  For some reason I think there is a mutex buried in there as well, but I'm not sure that there is...  I would ask on the Boost mailing lists for a better answer... it should be possible to replace the boost atomic operations with ones from TBB, again ask on the boost mailing list for more details.

In my experience, boost::shared_ptr had horrible performance.  However, this is all relative.  In my case, the pointers would increment and decrement millions of times in a short time...  the majority of my algorithm related to pointer manipulations, so it became a bottleneck in that case... which looking back on it I say "of course".  If you have a large number of pointers, which are being used a lot... I would consider a different approach, but of course that was just based on my experience, and code profiling revealed that something insane like 60% of execution time was spent on shared_ptr atomic operations.

I have written pointer containers that use TBB constructs instead, you might be interested in those.  They are used for exception safety, to call delete on all contained pointers if it goes out of scope.  Boost has something similar too.


Intel Software Network Forums Statistics

8473 users have contributed to 31605 threads and 100654 posts to date.
In the past 24 hours, we have 30 new thread(s) 110 new posts(s), and 160 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member Kevin Johnson