int main(int argc, char *argv[]) { if (argc != 3) { printf("usage: ./project1 [nrThreads] [iterations]\n"); return 1; } int num_cores = sysconf(_SC_NPROCESSORS_ONLN); printf("Number of cores: %d\n", num_cores); double elapsedTime; elapsedTime = markTime(); // The first argument is the number of threads executing simultaneously int nrThreads = atoi(argv[1]); // number of iterations performed in tfunc for each thread int iterations = atoi(argv[2]) / nrThreads; pthread_t thread_id[nrThreads]; int status, *p_status = &status; printf("%-25s| %-25s\n", "Number of threads", "Number of iterations"); printf("%-25d| %-25d\n", nrThreads, iterations); int i = 0; for (i = 0; i < nrThreads; ++i) { // generate threads // First argument: as each thread is created, its thread ID is saved in the thread_id array // Second argument: NULL - each created thread has the default set of attributes // Third argument: the function executed in the thread // Fourth: the argument passed to the function executed in the thread if( pthread_create(&thread_id[i], NULL, tfunc, (void*)iterations) > 0){ printf("pthread_create failure with Thread Nr. %d\n", i); return 2; } else { if(i %2 == 0) assignToCore(0, thread_id[i]); else assignToCore(1, thread_id[i]); } } for (i=0; i < nrThreads; ++i) { // wait for each thread // After the creation of the threads, the program waits for the threads to finish if ( pthread_join(thread_id[i], (void **) p_status) > 0){ printf("pthread_join failure with Thread Nr. %d\n", i); return 3; } // printf("Thread Nr. %d, Thread ID: [%d] returns\n", i, thread_id[i]); } elapsedTime = markTime() - elapsedTime; printf("Finished in %.3f seconds. \n", elapsedTime); return 0; }
void makeBasicScheduling(Core* core, List* alreadyQueue, int policy) { Job* job; switch (policy) { case ROUND_ROB: job = (Job*) get(*alreadyQueue, 0)->value; removeByIndex(alreadyQueue, 0); break; default: /*obtém o job que mais atendeu o critério de escalonamento*/ job = getGreatestCriterionJob(alreadyQueue); break; } //if(job != NULL) assignToCore(core, job); }