Previous | Next --- Slide 58 of 66
Back to Lecture Thumbnails
ishangaur

This seems like it could be really bad for performance. Is there a way to delegate the job of freeing to the last thread finished with a reference, after any of the threads indicates they would like to free the memory? (I guess as long as you won't accidentally end up coming back to that element in your next iteration before they do)

danieljm

@ishangaur, It sounds like std::shared_ptr may be what you would like. With a reference-counted smart pointer, memory is automatically freed after the reference count reaches zero. In general, having a per-thread hazard pointer shouldn't be bad for performance as long as the thread count is reasonably small, but for applications with several thousand threads there may be other more suitable techniques.

Please log in to leave a comment.