Commit 361f278e authored by bchareyre's avatar bchareyre

fix thread-unsafe assignment of permForceSynced by parallel ForceContainer...

fix thread-unsafe assignment of permForceSynced by parallel ForceContainer (https://answers.launchpad.net/yade/+question/690691)
parent 5bf85125
...@@ -104,25 +104,25 @@ void ForceContainer::addMaxId(Body::id_t id) ...@@ -104,25 +104,25 @@ void ForceContainer::addMaxId(Body::id_t id)
void ForceContainer::setPermForce(Body::id_t id, const Vector3r& f) void ForceContainer::setPermForce(Body::id_t id, const Vector3r& f)
{ {
ensureSize(id, -1); ensureSize(id, -1);
synced = false; if (permForceSynced) { // current permF has been accumulated already, substract it form total then add new value; else just set the value below
if (permForceSynced) { // current permF has been accumulated already, substract it form total, the new one will be added at next sync() addForceUnsynced(id, f -_permForce[id] );
addForce(id, -_permForce[id]);
} }
permForceSynced = false;
_permForce[id] = f; _permForce[id] = f;
permForceUsed = true; if (not permForceUsed) {
synced = false;
permForceUsed = true;}
} }
void ForceContainer::setPermTorque(Body::id_t id, const Vector3r& t) void ForceContainer::setPermTorque(Body::id_t id, const Vector3r& t)
{ {
ensureSize(id, -1); ensureSize(id, -1);
synced = false; if (permForceSynced) { // current permF has been accumulated already, substract it form total then add new value; else just set the value below
if (permForceSynced) { // current permF has been accumulated already, substract it form total, the new one will be added at next sync() addTorque(id, t -_permTorque[id] );
addTorque(id, -_permTorque[id]);
} }
permForceSynced = false;
_permTorque[id] = t; _permTorque[id] = t;
permForceUsed = true; if (not permForceUsed) {
synced = false;
permForceUsed = true;}
} }
const Vector3r& ForceContainer::getPermForce(Body::id_t id) { return ((size_t)id < size) ? _permForce[id] : _zero; } const Vector3r& ForceContainer::getPermForce(Body::id_t id) { return ((size_t)id < size) ? _permForce[id] : _zero; }
...@@ -193,9 +193,9 @@ void ForceContainer::sync() ...@@ -193,9 +193,9 @@ void ForceContainer::sync()
if (permForceUsed and not permForceSynced) { if (permForceUsed and not permForceSynced) {
_force[id] += _permForce[id]; _force[id] += _permForce[id];
_torque[id] += _permTorque[id]; _torque[id] += _permTorque[id];
permForceSynced = true;
} }
} }
permForceSynced = true;
synced = true; synced = true;
syncCount++; syncCount++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment