System universe;
pthread_t compute_thread;
-pthread_mutex_t mutex_terminate;
-bool terminate = false;
+pthread_mutex_t mutex_runstate;
+RUNSTATE runstate = RUN;
-void Cleanup_Threads(void); //Cleanup for threads
+void Thread_Cleanup(void)
+{
+ if (runstate == RUN)
+ QuitProgram(false);
+ pthread_join(compute_thread, NULL);
+}
// This is main function. Do not change it.
int main(int argc, char** argv)
numberOfProcessors = atoi(argv[2]);
}
- atexit(Cleanup_Threads);
+ atexit(Thread_Cleanup);
// Create a thread to handle computation loop
Graphics_Run(argc, argv); // Run graphics loop in the main thread
+ printf("Close!\n");
+ //We get to this point when the "close" button is clicked in the graphics window
+ QuitProgram(false);
+ pthread_join(compute_thread, NULL);
}
-/**
- * Function will be called when exit() is called.
- * Will set condition for child threads to terminate, and then join with them.
- * The main thread is responsible for calling exit().
- */
-void Cleanup_Threads()
-{
- printf("Set terminate\n");
- pthread_mutex_lock(&mutex_terminate);
- terminate = true;
- pthread_mutex_unlock(&mutex_terminate);
- pthread_join(compute_thread, NULL);
- pthread_exit(NULL);
-}