+ //create the threads
+ for(int i = 0; i < NUM_CORES; i++)
+ {
+ pthread_create(&thread_ids[i], NULL, &proth_thread, NULL);
+ }
+
+ //lock main thread until prime is found
+ pthread_mutex_lock(&found_lock);
+ pthread_mutex_lock(&found_lock);
+
+ //destroy the threads
+ for(int i = 0; i < NUM_CORES; i++)
+ {
+ pthread_cancel(thread_ids[i]);
+ }
+
+ //destroy the mutexes
+ pthread_mutex_destroy(&n_lock);
+ pthread_mutex_destroy(&found_lock);
+
+ time(&end);
+ printf("total time: %f seconds\n", difftime(end, start));
+}
+
+unsigned long get_n()
+{
+ pthread_mutex_lock(&n_lock);
+ unsigned long n = n_val;
+ n_val++;
+ pthread_mutex_unlock(&n_lock);
+ return n;
+}
+
+static void * proth_thread(void *arg)
+{
+ // variables to test the primality
+ mpz_t t;
+ mpz_t t_exp;
+ mpz_t t_p1;
+ mpz_t t_p2;
+ mpz_t t_p3;