Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago

Question

=+Are you interested in working on global teams?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago