Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2466 Discussions

TBB in an already threaded application exception

scasey67
Beginner
407 Views
I am using TBB in an already threaded application on a Windows (XP, 32 bit) machine. When the parallel_for finishes, I get an exception thrown from spawn_root_and_wait(). Below is my code.

[bash]concurrent_unordered_map Components;

struct UpdateComponents
{
	float Data;
	
	UpdateComponents(float delta_t): Data(delta_t) {};

	void operator() (concurrent_unordered_map::range_type& range) const
	{
		for (concurrent_unordered_map::const_iterator iter = range.begin(); iter != range.end(); ++iter)
		{
			iter->second->update(Data);
		}
	}
};

void ComponentManager::updateComponents(float delta_t)
{
	task_scheduler_init init;
	if (delta_t > 0.0f)
	{
		// Update the components
		parallel_for(Components.range(), UpdateComponents(delta_t));
	}
}


[/bash]


This code sits in a DLL that the already threaded application calls. With a single threaded test application I don't have any issues, just when the DLL is with the target application. I must be missing something somewhere and I have been combing through the documentation. Any help is appreciated, thank you.

(note: the code above is littered with 'lt' and 'gt' and not '<' and '>')
0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
407 Views
Try making a test call to your DLL before yourapplication code instantiates its additionalthreads. Have this call perform some innocuous parallel_for or some internal function that established the TBB thread team.

Then see if the next call to your DLL, after establishing your application thread team, succeeds or fails

Jim Dempsey
0 Kudos
scasey67
Beginner
407 Views
Thank you for the response. I cannot do as you have recommended as I do not have access to source for the application (commercial game engine, our license doesn't include source) - just an API.
0 Kudos
scasey67
Beginner
407 Views
Answered my own question.

It wasn't TBB that was the problem, but the metadata that is read in from an XML file forconstructing the ComponentInstance objectsthat was different from the test data.

Strange that the crash happened within a TBB function call whenit was really a null pointer in the simulation. The stack trace showed no indication of this. The way that I found it was to comment out the parallel_for calls and iterated across the containers in the'ye olde fashioned' way and found the culprit.
0 Kudos
jimdempseyatthecove
Honored Contributor III
407 Views
Quoting scasey67
Thank you for the response. I cannot do as you have recommended as I do not have access to source for the application (commercial game engine, our license doesn't include source) - just an API.

I saw your other post for the work around.....

However regarding my earlier response

// yourProgram.cpp
...
int main(int argc, int argv[])
{
yourFunctionToInitializeTBBandRunBogus_parallel_for();
...
someCallTo3rdPartyGameEngine());
...
yourTBBcodeContainingCallsToSome3rdPartyGameEngine());
...
}

You do not need the sources to the 3rd party library

0 Kudos
scasey67
Beginner
407 Views

Thanks Jim, I probably wasn't too clear in my post. The work around was for easier debugging (unable to view the data in the concurrent_unordered_map in quick view (VS 2008)). The problem was a malformed object, we fixed the data and have the concurrent methods back in there and everything isworking fine now.

Also, the game engine is where the main() function resides, our DLL is accessed through a game engine DLL: GameEngine.exe -> GameServer.dll -> Our.dll. OurDLLjust sends and receives messages from the server dll and does its own work on our data.

Again, thanks for responding to the thread!

0 Kudos
Reply