reactphysics3d icon indicating copy to clipboard operation
reactphysics3d copied to clipboard

Instantiate multiple PhysicsCommon instances

Open lodgegao opened this issue 2 years ago • 4 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.

lodgegao avatar May 04 '23 11:05 lodgegao

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.

DanielChappuis avatar May 09 '23 09:05 DanielChappuis

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 ?

lodgegao avatar May 09 '23 11:05 lodgegao

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.

DanielChappuis avatar May 09 '23 11:05 DanielChappuis

Got it. Thanks a lot !

lodgegao avatar May 09 '23 11:05 lodgegao

I am closing this issue. Do not hesitate to reopen it if necessary.

DanielChappuis avatar Jun 14 '24 05:06 DanielChappuis