Click here to Skip to main content
12,252,427 members (58,739 online)
Click here to Skip to main content

Tagged as

Stats

26K views
332 downloads
39 bookmarked
Posted

Testing simple concurrent containers

, 25 Oct 2009 CPOL
This article illustrates simple approaches and test results when creating containers with concurrent flavor and running on a multi-core PC.
#pragma once
#include "tbb/concurrent_hash_map.h"

template <typename key_type, typename value_type>
class TBB_map_t 
{
public:
	
	inline bool insert( const std::pair<key_type, value_type>& pair) 
	{
		return m_map.insert(pair);
	}

	inline bool erase(const key_type& _key)
	{
		return m_map.erase(_key);
	}

	bool update(const key_type& _key, const value_type& _val)
	{
		TBB_map::accessor accessor;
		if (m_map.find(accessor, _key))
		{
			accessor->second = _val;
			return true;
		}
		else
		{
			return false;
		}
	}

	bool find(const key_type& _key, value_type& _val)
	{
		TBB_map::const_accessor accessor;
		if (m_map.find(accessor, _key))
		{
			_val = accessor->second;
			return true;
		}
		else
		{
			return false;
		}
	}
private:	
	typedef tbb::concurrent_hash_map<key_type, value_type> TBB_map;
	TBB_map m_map;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Valery Grebnev
Software Developer
Canada Canada
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 25 Oct 2009
Article Copyright 2009 by Valery Grebnev
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid