+ // Each thread runs until the whole program is supposed to end
+ while (!ExitCondition())
+ {
+
+
+ System_Forces(s, &universe); // Each thread computes the forces for its share of bodies
+
+ // Do not confuse with "Barrier_Wait".
+ // Barrier_Wait does not affect the barrier; it just waits for it
+ // Barrier_Join actively updates the state of the barrier, and wakes up sleeping threads if required.
+
+ Barrier_Join(&force_barrier); // All threads must reach here before moving on.
+ if (ExitCondition()) return NULL;
+
+
+ //fprintf(stderr,"Thread %p - force barrier finished\n", arg);
+ //printf("Computed ALL forces\n");
+
+
+ // If required, wait for the graphics to finish drawing stuff
+ if (options.draw_graphics && options.pedantic_graphics)
+ {
+ //printf("Worker %p waits on graphics barrier\n", arg);
+ Barrier_Wait(&graphics_barrier);
+ //printf("\tWorker %p wakes up after graphics barrier\n", arg);
+ if (ExitCondition()) return NULL;
+ }
+
+
+
+ Barrier_Enter(&position_barrier);
+ System_Positions(s); // Each thread updates the positions for its share of bodies
+
+
+ // Barrier_JoinCall behaves in the same way as Barrier_Join, except the *last* thread
+ // (ie: the one that wakes up the others) also calls the function with arguments given.
+ Barrier_JoinCall(&position_barrier, StepFunction, (void*)(&universe));
+ if (ExitCondition()) return NULL;
+ //Barrier_Join(&position_barrier);
+
+ // All threads have computed positions, and *one* thread calls StepFunction()
+