Question: I have an assignment to create a multi-threaded event scheduler in C. I spawned two threads in main using pthread_create() . My first thread asks
I have an assignment to create a multi-threaded event scheduler in C. I spawned two threads in main using pthread_create() . My first thread asks for input requests and stores that input to a minHeap. The input request is a time interval in seconds and a string, example would be "2 two","3 three". When the user types "done" a timer starts, when a SIGALRM occurs, the second thread kicks in and removes a few events from the minHeap based on the time they were placed in there. MY issue is, when the SIGALRM comes and kicks in and the second thread ends, my program just sits idle when I want it to go back to the first thread and start asking for input requests again.
In psedocode:
main(int argc, char * argc[])
1.get initial time and request from command line
2.spawn two threads, one called reader and one called scheduler
void * reader(void * args)
1.prompt user for input
2.add input to minHeap
3.when user types "done" , have a timer start
4. When SIGALRM occurs, invoke signal handler which forces program to go to thread scheduler
void * scheduler(void * args)
1. wait for SIGALRM using sem_wait(sem1)
2.pause timer
3. remove events from minheap based on time they were put in
4. Start timer
Want to go back to thread reader to begin asking for input again but I dont know how.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
