Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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.
container_locks.zip
Container_locks
src
Testing_simple_concurrent_containers.pdf
VC9
container_locks.vcproj.val-PC.val.user
Debug
tbb_debug.dll
Debug64
tbb_debug.dll
Release
tbb.dll
Release64
tbb.dll
#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

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