Hi there,
is there an example or documentation about how to synchronize multiple threads in a particle plugin by the RF Mutex Object available? The SDK documentation isn't very detailed on this issue.
Thank you very much,
Martin
Multi-Thread example
Re: Multi-Thread example
Hello, you must have a mutex object as a member variable of your plugin, this way the same mutex is shared and used by all the threads that your plugin is spawning.
I hope this helps.
Code: Select all
using namespace nextlimit::rf_sdk;
class MyParticleSolverPlgSdk : public ParticleSolverPlgSdk
{
Mutex mutex_;
virtual void computeInternalForces( ParticleSolver* particleSolver,
PB_Emitter* emitter,
int nThread,
RFEmitter_It iter )
{
mutex_.lock();
// SAFE ACCESS TO SHARED RESOURCE
mutex_.unlock();
}
};
Angel Tena
Head of RealFlow Technology
Next Limit Technologies
Head of RealFlow Technology
Next Limit Technologies
Re: Multi-Thread example
Hello,
thanks for your really helpful reply. One question is still left: what about, if I want to make sure, that all threads are waiting until a certain passage is finished by the last of them? To become a little more detailed, supposed I have a member object o of a class X, which is constructed in precomputeInternalForces([...]). O knows about how many threads are used during simulation from scene.getNumberOfThreads(), which is passed as a constructor parameter. X defines a method
o.doSomething(nThread) is called by computeInternalForces,
and two private methods
How do I make sure, that no thread starts executing subB() unless all the other threads have finished executing subA()?
Thanks a lot in advance,
Martin
thanks for your really helpful reply. One question is still left: what about, if I want to make sure, that all threads are waiting until a certain passage is finished by the last of them? To become a little more detailed, supposed I have a member object o of a class X, which is constructed in precomputeInternalForces([...]). O knows about how many threads are used during simulation from scene.getNumberOfThreads(), which is passed as a constructor parameter. X defines a method
Code: Select all
public: void doSomething(int threadId)
{
this->subA();
this->subB();
}
and two private methods
Code: Select all
private: void subA(){...}
private: void subB(){...}
Thanks a lot in advance,
Martin