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(void);
17 void QuitProgram(bool error);
20 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
22 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
23 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
27 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
29 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread.
30 extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
32 extern pthread_t * worker_thread; //Array of worker threads responsible for Force and Position updates
33 extern System * sub_system; //Array of Systems used to divide up the main "universe" System for worker threads
34 extern pthread_mutex_t mutex_workers;
35 extern pthread_cond_t workers_done_cv;
36 extern unsigned workers_busy;
38 #endif //_NBODY_MTHREAD_H