Instantiate multiple PhysicsCommon instances
lodgegao opened this issue · comments
Hi Daniel. I read the issues and discussions with themes about thread safety, and you said that reactphysics3d is not thread safe currently and does not support multithreading yet. And, in the comments of the source code, it is strengthened again that the PhysicsCommon object should be instanced only once in the beginning of application.
But after reading the source code, I found that I can probably bypass the problem of thread safety by instantiating multiple PhysicsCommon objects, with each thread instantiating its own PhysicsCommon object. And I did an experiment in the main thread that two PhysicsWorld objects were created from two different PhysicsCommon objects, in which I added multiple rigid bodies and joints, and there was no weird behaviors.
I wonder if creating multiple PhysicsCommon objects is legal and I could apply this method to avoid the problem of thread safety, or is there any problem I didn't take into consideration? Thank you.
Hello,
I would say it's not safe to instanciate multiple PhysicsCommon
instances. As you can see, this class contains some static fields that are designed to be unique.
Yeah I had the same worry too, but I found that the only static member of PhysicsCommon is the logger, and static members related to memory allocators are all constants. So does that mean if I choose not to assign any value to the logger, it would be safe ?
Maybe currently yes but I would still advice not to use multiple PhysicsCommon
instances in the future because I have never tested this and will never test this. I prefer to work on PhysicsCommon
to make it thread safe in the future.
Got it. Thanks a lot !
I am closing this issue. Do not hesitate to reopen it if necessary.