Access violation using "insert" on concurrent_unordered_map

Access violation using "insert" on concurrent_unordered_map

FredP's picture

Trying to store a key, value pair in a concurrent_unordered_map which needs concurrent insertion capabilities. The following code is the function that is failing at run-time with an Access Violation error:

void EEconomy::CreateProductNetwork( std::vector entries )
{
	//scroll through each item in the list and build the network
	for(std::vector::const_iterator i = entries.cbegin(); i != entries.cend(); ++i)
	{
		EEconomy::networkEntry currentEntry = *i;
		EProductClass* product = new EProductClass(currentEntry.productID, currentEntry.productName, currentEntry.ancestors, currentEntry.successors);

		std::pair ins(currentEntry.productID, product);

		this->productMap.insert(ins);

	}

}
The last line is the failing one. In the EEconomy header file, the productMap definition is:
	concurrent_unordered_map productMap;

No problem building the code, but I'm obviously making a mistake. Unfortunately, I can't work it out from the reference guide and there seem to be no examples. What (probably obvious) mistake am I making? Fred

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Anton Malakhov (Intel)'s picture

Fred, the code from your post looks fine. Probably, the problem lurks somewhere else. How do you use the map before this insertion? How productMap is initialized (any constructor or rehash() arguments)? Could you say where exactly access violation occurs inside TBB's code? Can you see the stack? Also, what version of TBB do you use? What's compiler version?

FredP's picture

I suspect this is where I'm going wrong, and was uncomfortable about this beforehand! The productMap is unused beforehand, and I don't use any constructors for it - the declaration is as in my post above, and the code snippet is its first use. I'm using TBB v3 Update 5, and VC++ 2010. The violation occurs in: > WorldSim.exe!__TBB_machine_load_store<__int64,8>::load_with_acquire(const __int64 & location) Line 553 + 0x5 bytes C++ which traces back through a series of additional TBB calls to my code. I suspect my failure is in initialising the unordered_map, but if so, can someone give me a simple code snippet for using the container, and I'll adapt it back to my use case. For convenience, the entire call stack is: > WorldSim.exe!__TBB_machine_load_store<__int64,8>::load_with_acquire(const __int64 & location) Line 553 + 0x5 bytes C++ WorldSim.exe!__TBB_load_with_acquire<__int64>(const __int64 & location) Line 604 C++ WorldSim.exe!tbb::internal::atomic_impl::operator unsigned __int64() Line 201 + 0xa bytes C++ WorldSim.exe!tbb::interface5::internal::concurrent_unordered_base,std::equal_to >,tbb::tbb_allocator >,0> >::internal_insert(const std::pair & value) Line 1110 + 0x14 bytes C++ WorldSim.exe!tbb::interface5::internal::concurrent_unordered_base,std::equal_to >,tbb::tbb_allocator >,0> >::insert(const std::pair & value) Line 856 + 0x14 bytes C++ WorldSim.exe!EEconomy::CreateProductNetwork(std::vector > * entries) Line 43 + 0x26 bytes C++ fred

Anton Malakhov (Intel)'s picture

So, it fails on the first read of a plain member of the container class (atomic "my_number_of_buckets"). It means that 'this' pointer is wrong, and the problem does not relate to TBB. It seems like CreateProductNetwork() is called via bad (null) pointer to EEconomy class.

FredP's picture

That's great - it's because EEconomy is a Singleton and it transpired that I'd screwed up the initialisation. I was uncertain though, because I was worried I'd misused the container, so tried debugging that first. Sorry if this wasted your time (such a simple error) - but it helped me a great deal! Fred

Login to leave a comment.