c++ - An intrusive list of unique_ptrs? -
i have program highly multi-threaded , contains intrusive linked list of objects. need pass off objects in list several threads, 1 thread ever own object @ time, meaning don't need object or pointer shared.
i wanted create intrusive list unique_ptr using boost, i've read unique_ptr not compatible boost intrusive library not have right ownership semantics.
per this intrusive library requires it's elements (pointers) have same ownership semantics raw pointer. unique_ptr or shared_ptr not qualify.
i wondered if give me advice on how best implement intrusive list can safely pass elements through several threads , know being moved thread , not shared amongst threads?
as far follow, work need kind of auto-unlink hooks.
since intrusive container not own objects contains, should not have problem adding raw pointers unique_ptrs refer to, intrusive container.
if need able access actual unique_ptr raw pointer in intrusive list, along lines of enable_shared_from_this might help. (you'd need combine intrusive container intrusive unique_ptr.)
after thinking bit seems there isn't intrusive unique_ptr variant out there, since "intrusive" part smart pointers reference count, , unique_ptr objects not have reference count.
probably best of using shared_ptr this, since has enabled_shared_from_this.
Comments
Post a Comment