1 #ifndef _NBODY_MTHREAD_H
2 #define _NBODY_MTHREAD_H
5 #include "../single-thread/nbody.h" //Use original simulation code
11 #define DEFAULT_WORKING_THREADS 2
13 //Undefine default macros, replace with functions
15 void Simulation_Run(int argc, char ** argv);
17 void QuitProgram(bool error);
25 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
27 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
28 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
32 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
34 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread.
35 extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
37 extern pthread_t * worker_thread; //Array of worker threads responsible for Force and Position updates
38 extern System * sub_system; //Array of Systems used to divide up the main "universe" System for worker threads
39 extern pthread_mutex_t mutex_workers;
40 extern pthread_cond_t workers_done_cv;
41 extern unsigned workers_busy;
43 extern pthread_mutex_t mutex_graphics; // Mutex for graphics
44 extern pthread_cond_t graphics_cv; //Condition used to start graphics or computation thread from the other
45 extern bool graphics_busy;
47 #endif //_NBODY_MTHREAD_H