|
From: Max K. <kh...@gm...> - 2013-03-06 12:55:19
|
Hi,
You can pass any extra data into SkipListMap::ensure using a functor and
boost::ref (or cds::ref).
For example:
struct myUpdateFunctor {
anytype myExtraData ;
void operator()( bool bNew, cds::container::SkipListMap<...>::value_type
<imap://khizmax%40gmail%2E...@im...:993/fetch%3EUID%3E/%5BGmail%5D/%26BB4EQgQ%2CBEAEMAQyBDsENQQ9BD0ESwQ1-%3E467?part=1.2.2&filename=classcds_1_1container_1_1_split_list_map.html>&
item )
{
// Here you may use myExtraData to update item
}
};
cds::container::SkipListMap<...> myMap ;
myUpdateFunctor myFunc ;
myFunc.myExtraData = ... ;
myMap.ensure( key, cds::ref( myFunc )) ;
cds::ref is used to pass myFunc by reference.
If your compiler supports C++11 you can use a lambda function instead of
myUpdateFunctor object.
Note that SkipListMap does not guarantee atomic update of map items, it
guarantees atomic update of map only.
Atomic modification on item level you should provide yourself. libcds
only guarantees that item passed will not be deleted by any other thread
while you are changing the item.
/> By the way, is there a plan to implement a gc::nogc version of
SkipLists (no delete support is ok) ? Can I use the current one without
garbage collection and not doing any deletes?//
/
SkipList<cds::gc::nogc> will be ready in the next release. However, you
may use current GC-based implementation freely.
Just nogc-based implementation is more lightweight and has different
interface closer to traditional programming like std.
Best regards,
Max
On 03/06/2013 02:58 PM, Vaivaswatha N wrote:
> Hi,
>
> I'm trying to use the SkipListMap provided by libcds. My goal is to be
> able to update a value atomically when the key is already present.
> (I'm trying to implement a sparse bit vector on top of the SkipListMap
> and hence will need to atomically set bits)
>
> When inserting a key/value paper, if the key is already present, the
> SkipListMap interface "insert()" will call a user-provided functor if
> the item is already present. However, the signature of the functor is
> such that it doesn't allow me to pass any other external data.
> So I'm restricted to update the value atomically by only knowing the
> current value (without any other input).
>
> On the other hand, if I use LazyKVList or MichaelKVList, I can do this
> by calling "ensure()" which will return an iterator. I can use the
> iterator to atomically update my value.
>
> I'm interested to know if there is anyway to update values atomically
> when the key is present (for SkipListMap).
>
> By the way, is there a plan to implement a gc::nogc version of
> SkipLists (no delete support is ok) ? Can I use the current one
> without garbage collection and not doing any deletes?
>
> Thanks a lot,
>
> --
>
> - Vaivaswatha
|