raisimTech / raisimLib

Visit www.raisim.com
http://www.raisim.com
Other
341 stars 91 forks source link

Help to understand the mutex #468

Closed DeFilMat closed 1 year ago

DeFilMat commented 1 year ago

Hi, I am studying for my first time raisim, and I was wondering what's the purpose of this portion of code in the Environment.hpp function provided by raisim:

    for(int i=0; i< int(control_dt_ / simulation_dt_ + 1e-10); i++){
      if(server_) server_->lockVisualizationServerMutex();
      world_->integrate();
      if(server_) server_->unlockVisualizationServerMutex();
    }

I tryed to read the documentation to understand better what is world.integrate() and these mutex, but probabily I have a lacunarty in this field.

jhwangbo commented 1 year ago

If you read about C++ mutex, you will get its purpose. But to simply put, lockVisualizationServerMutex means "Hey visualizer, I am going to modify the simulation variables so don't read them now" and unlockVisualizationServerMutex means "Hey visualizer, I finished modifying the simulation variables. You can read them now".

the visualizer is running in another thread and has to know when it is safe to read the simulation variables for visualization.