9 unsigned numberOfProcessors;
12 pthread_t compute_thread;
13 pthread_mutex_t mutex_terminate;
14 bool terminate = false;
16 void Cleanup_Threads(void); //Cleanup for threads
18 // This is main function. Do not change it.
19 int main(int argc, char** argv)
23 printf("Please provide the filename, i.e. \'%s bodiesfield.dat\'\n", argv[0]);
28 System_Init(&universe,argv[1]);
29 atexit(Universe_Cleanup);
33 numberOfProcessors = atoi(argv[2]);
36 atexit(Cleanup_Threads);
38 // Create a thread to handle computation loop
40 if (pthread_create(&compute_thread, NULL, Compute_Thread, (void*)&universe) != 0)
42 perror("Error creating compute thread");
46 Graphics_Run(argc, argv); // Run graphics loop in the main thread
52 * Function will be called when exit() is called.
53 * Will set condition for child threads to terminate, and then join with them.
54 * The main thread is responsible for calling exit().
56 void Cleanup_Threads()
58 printf("Set terminate\n");
59 pthread_mutex_lock(&mutex_terminate);
61 pthread_mutex_unlock(&mutex_terminate);
62 pthread_join(compute_thread, NULL);