Click to See Complete Forum and Search --> : a concurrent list with smart pointers in a multithread environment (copy)


mpfidalgo
June 27th, 2007, 12:02 PM
hi,
I send this post to two diferents forums becuase I'm not sure where place it:
a) Multithreading
b) C++ (Non Visual C++ Issues)

if some admin must remove one of them, please do it. :-)

the problem:

I'm building a concurrent list in c++ (boost or zthreads as underlying library, for mutex, wait and signal operations), first I use raw pointers, but if two differents threads want to delete the some node of the list, the first node can do it and update the content of the iterator:

// Make the delete operation
delete e._M_node;
// Update the content (point to null) of the iterator
e._M_node=0;

but the other thread still have a pointer (e._M_node, for instance) point to ?¿?¿?¿?¿? (only bjarne knows), I used an iterator counter on each node to prevent this situation (only can remove a node where its _Iterator_Counter==0) but ONLY in this case this solution fails because I need a reference counter instead.

question a) another solution instead of a reference counter???

then I am trying to use share pointers [http://www.boost.org/libs/smart_ptr/shared_ptr.htm] a boost class of smart pointers but I have too many troubles, the most important:

the head and the tail of the double linked concurrent list:

boost::shared_ptr<_List_node<_Tp> > _List_head;
boost::shared_ptr<_List_node<_Tp> > _List_tail;

template<typename _Tp>
concurrentList<_Tp>::concurrentList(
): _List_head( ), _List_tail( ){
_List_head->_M_next=_List_tail;
_List_tail->_M_prev=_List_head;
}

this compile but it doesn't work becuase _List_head and _List_tail are null, but in the other hand I must not do a new because these are only dummy items. And, of course, I know that they are circular references, but if I achieve that the code works I will change to weak_ptr.

question b) some idea??