int main(int argc, char**argv) { int i; char * name = "Thread-X"; char * names[5]; for(i = 0; i < 5; ++i) { names[i] = malloc(9); strcpy(names[i], name); names[i][7] = i + '1'; } mutex_init(&m); scheduler_begin(); for(i = 0; i < 5; ++i) { thread_fork(increment_and_print, names[i]); } scheduler_end(); int array_consistent = 1; for(i = 0; i < 50; ++i) { if(shared_array[i] != i) { array_consistent = 0; break; } } printf(array_consistent ? "results are consistent.\n" : "results are inconsistent!\n"); return 0; }
int main(void) { scheduler_begin(); go1(); scheduler_end(); return 0; }
int main(void) { scheduler_begin(); int n1 = 20000, n2 = 10000, n3 = 30000; thread_fork(print_nth_prime, &n1); thread_fork(print_nth_prime, &n2); thread_fork(print_nth_prime, &n3); scheduler_end(); }
int main(void) { scheduler_begin(); struct array * A = rand_array(1000000); seq_threshold = 100; printf("before sort: %s\n", check_sort(A)); par_mergesort(A); printf("after sort: %s\n", check_sort(A)); scheduler_end(); return 0; }
int main(void) { mutex_init(&m); scheduler_begin(5); thread_fork(increment, (void*)"1"); thread_fork(increment, (void*)"2"); thread_fork(increment, (void*)"3"); thread_fork(increment, (void*)"4"); thread_fork(increment, (void*)"5"); scheduler_end(); printf("shared_counter = %d\n", shared_counter); // printf("%s\n", "main_thread: return"); }
int test_scheduler() { shared_counter = 0; struct thread_t* threads[5]; scheduler_begin(2); threads[0] = thread_fork(increment, (void*)"1"); threads[1] = thread_fork(increment, (void*)"2"); threads[2] = thread_fork(increment, (void*)"3"); threads[3] = thread_fork(increment, (void*)"4"); threads[4] = thread_fork(increment, (void*)"5"); scheduler_end(); //free threads' memories int i; for (i=0;i<5;i++) { thread_free(threads[i]); } //check if the result is correct if (shared_counter != 100*5) { return -1; } return 0; }