mardi 6 janvier 2015

threadsafe wrapper on std::unordered_map

I am trying to implement a thread safe wrapper class on top of std::unordered_map is it safe to have begin and end functions as below?



std::unordered_map<Key, T, Hash, Pred, Alloc> umap;
iterator begin() {
return umap.begin();
}
iterator end() {
return umap.end();
}


Also please comment if there is any obvious mistakes in copy/move operator= implementation



concurrent_unordered_map& operator=(const concurrent_unordered_map& other) ;
{
if (this!=&other) {
std::lock(entry_mutex, other.entry_mutex);
std::lock_guard<boost::shared_mutex> _mylock(entry_mutex, std::adopt_lock);
std::shared_lock<boost::shared_mutex> _otherlock(other.entry_mutex, std::adopt_lock);
umap = other.umap;
}
return *this;
}
concurrent_unordered_map& operator=(concurrent_unordered_map&& other)
{
if (this!=&other) {
std::lock(entry_mutex, other.entry_mutex);
std::lock_guard<boost::shared_mutex> _mylock(entry_mutex, std::adopt_lock);
std::shared_lock<boost::shared_mutex> _otherlock(other.entry_mutex, std::adopt_lock);
umap = std::move(other.umap)
}
return *this;
}


Thanks MJV


Aucun commentaire:

Enregistrer un commentaire