, , , , , , , , , , () () .
, , - :
while (true) foreach (object in simulation) {
auto new_object = object;
SomeComplicatedPhysicsIntegrationInPlace(new_object)
atomic_swap(object, new_object);
}
Alternativelty, , . :
/* Psudocode */ while (true) { simulation [1-global_active_idx] = simulation [global_active_idx]; foreach ( [global_inactive_idx]) { SomeComplicatedPhysicsIntegrationInPlace (); } global_active_idx = 1-global_active_idx;// , }
[global_active_idx].
. , , , 1 , 0, , . , . , volatile, , .
, , , , , ++ ++ 0x, , " int" ARE , .
, , atomic_swap , (a) , , , , , , () , , . http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
, . , , 0 1; . ( ), , , .
, . - , , ? - , , , ? ?