Problem with multithreading

jjohansen
Posts: 2
Joined: Thu May 24, 2007 12:47 pm

Problem with multithreading

Post by jjohansen »

Hi i'm trying to get two "physics worlds" to run in two different POSIX threads. It all works when i disable one of the threads, but when i enable both and they have both reached:
dynamicsWorld->stepSimulation(stepSize)

the program crashes with the following error:
Bullet/Source/bullet-2.46/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h:95: failed assertion `index < m_cachedPoints'
The application is built on the DemoApplication class, from the bullet demos, like this:

Code: Select all

class JJ_App : public DemoApplication
My thread spawning function look like this:

Code: Select all

void *spawnThread(void* arg)
{
	JJ_App* appInstance = NULL;

	char filename[50];
	switch((int) arg)
	{
		case 1:
			printf("Thread 1 says Hello\n");
			myJJ_App1 = new JJ_App();
			appInstance = myJJ_App1;
			strcpy(filename,"testResult1.jjres");
			break;
		case 2:	
			printf("Thread 2 says Hello\n");		
			myJJ_App2 = new JJ_App();
			appInstance = myJJ_App2;
			strcpy(filename,"testResult2.jjres");
			break;
		default:
			printf("ARRRRGH :)\n");
			break;
	}
		
	appInstance->initPhysics();	
	appInstance->initTest( (int) arg,0.5f,0.5f,PI/4.0f,0.021227f,filename);
	appInstance->threadLoop(); //including stepSimulation() and test analysis
	
	return NULL;
	
}

I run the application without the openGL part, why I'm only interrested in the results of the physics tests. The reason for me to do this multithreading is to exploit both kernels on multiprocessor systems. The two physics enviroment (including bullet with use of GIMPACT) is supposed to be created in two completely different instances, but it seems like the two threads are sharing something? Why else would they crash only when they're both executing? Can anybody help? Don't really know what to conclude from the error.
Btw. the stacksize of the threads has been set to be large enough to room the instances.
Thx - Jonas
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Does it work without GIMPACT? For moving concave objects, it is recommended to use btCompoundShape and add convex parts (convex decomposition).

Just to let you know: there is already a parallel Bullet version for Playstation 3 SPUs, with more fine grained parallelism. The planned public version of Bullet 3.0 will include parallelism out-of-the-box.

Thanks,
Erwin
jjohansen
Posts: 2
Joined: Thu May 24, 2007 12:47 pm

Post by jjohansen »

Thx for answering...
Does it work without GIMPACT?
No, have just tried without GIMPACT, created 10 falling boxes in each world, and only the stepSimulation() in each threadloop. Same error.
For moving concave objects, it is recommended to use btCompoundShape and add convex parts (convex decomposition).
Yea, I know - but I have to be able to change the shape of my meshes at runtime. Isn't that hard to do fast and precise when you use convex decomposition? I'm really not that familiar with convex decomposition, are you using editors to do that, or do you know libraries that do PRECISE decomposition pretty fast? I've done some decomposition with a library, but it was slow and a really poor approximation.
UPDATE: Searched the forum and got my answer :)
Just to let you know: there is already a parallel Bullet version for Playstation 3 SPUs, with more fine grained parallelism. The planned public version of Bullet 3.0 will include parallelism out-of-the-box.
Looking forward to it, but I would still like this to work ;)[/b]