Computer Science > Research Paper > Wilfrid Laurier UniversityCP 386A3.txt (All)
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <sys/stat.h> #include <time.h> //Angela Tran //180392140 //tran2140 void logStart... (char* tID);//function to log that a new thread is started void logFinish(char* tID);//function to log that a thread has finished its time void startClock();//function to start program clock long getCurrentTime();//function to check current time since clock was started time_t programClock;//the global timer/clock for the program sem_t global; sem_t even; sem_t odd; int curr = 0; int prev = 0; typedef struct thread //represents a single thread, you can add more members if required { char tid[4];//id of the thread as read from file unsigned int startTime; int state; pthread_t handle; int retVal; } Thread; //you can add more functions here if required int threadsLeft(Thread* threads, int threadCount); int threadToStart(Thread* threads, int threadCount); void* threadRun(void* t);//the thread function, the code executed by each thread int readFile(char* fileName, Thread** threads);//function to read the file content and build array of threads int main(int argc, char *argv[]) { if(argc<2) { printf("Input file name missing...exiting with error code -1\n"); return -1; } //you can add some suitable code anywhere in main() if required //initilization sem_init(&global, 0, 1); sem_init(&even, 0, 1); sem_init(&odd, 0 ,1); Thread* threads = NULL; int threadCount = readFile(argv[1],&threads); startClock(); while(threadsLeft(threads, threadCount)>0)//put a suitable condition here to run your program [Show More]
Last updated: 1 year ago
Preview 1 out of 4 pages
Instant download
Instant download
Connected school, study & course
About the document
Uploaded On
Jul 08, 2021
Number of pages
4
Written in
This document has been written for:
Uploaded
Jul 08, 2021
Downloads
0
Views
42
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·