Question: Programming in C Synopsis In this assignment, you will have a process that will create multiple threads at different times. These threads may have different

 Programming in C Synopsis In this assignment, you will have a

Programming in C

Synopsis In this assignment, you will have a process that will create multiple threads at different times. These threads may have different start_time and lifetime. Once all the threads are over, the process will terminate. There are three tasks that should be performed: Read the input file that contains thread properties: ID, start time and lifetime. Create a thread whenever it is the start time of some thread. All the threads implement run same function. Implement this function so that the thread should terminate when it has consumed time units equal to its lifetime. Description For this assignment, you are provided a skeleton code in the file student_code.c. Some functions are completely implemented, some are partially and for some only header is provided. Additionally, you can write your own functions if required. Complete the program as per the following details so that we can have functionality as described in Synopsis as above. Write all the code in single C file: 1. The program has its local clock mechanism. You must invoke startClock() when you are ready to service threads. The file reading should be performed before this. Once the startClock() is invoked, the getCurrentTime() can be invoked to see how much time units are passed since startClock() was invoked. This will provide a local clock ticks behavior to service your threads. 2. The thread information will be provided to this program in a text file. You must accept the name of this file as command line argument. In this file, there will be one thread information per line. Each thread information has three attributes provided in the order: thread_id;start_time; lifetime. It is not necessary that the individual thread lines are in any specific order.start_time indicates that at what time a thread should be created and started lifetime is the time units for which a thread must stay alive. Use the methods in step 1 in a suitable way to implement this functionality. 3. To read the file, readFile() function is provided. However, it has a small part missing that you must complete so that the thread attributes can be stored in memory in a suitable way. This also requires the completion of struct thread. Add suitable members to struct thread and the store the content of the file in a suitable data structure. 4. Once you have thread information in memory, start servicing the threads using the suitable POSIX library calls. main() is provided but you have to complete it in a suitable way. The program will keep running if there are some threads which are not yet created or if there are some running threads. 5. The threadRun() is the function that each thread must run. Implement this function so that each thread takes care of its lifetime and terminates when that is over. 6. The image below shows the expected output for the sample input file provided with this assignment: pscubuntu: cp386/a2$ .Assignment_1 samplez in.txt 111 Mew Thread with ID 118 is started. IZ1 Merw Thread uith ID t2 ix started 151 Mew Thread with ID ti is started 191 Thread with ID t2 is finished. [10] Thread with ID ti is finished. [16] Thread with ID tie is finished. (20) New Thread with ID t22 is started [25] Thread with ID t22 is finished. psc@ubuntu:cp386/a2$ Synopsis In this assignment, you will have a process that will create multiple threads at different times. These threads may have different start_time and lifetime. Once all the threads are over, the process will terminate. There are three tasks that should be performed: Read the input file that contains thread properties: ID, start time and lifetime. Create a thread whenever it is the start time of some thread. All the threads implement run same function. Implement this function so that the thread should terminate when it has consumed time units equal to its lifetime. Description For this assignment, you are provided a skeleton code in the file student_code.c. Some functions are completely implemented, some are partially and for some only header is provided. Additionally, you can write your own functions if required. Complete the program as per the following details so that we can have functionality as described in Synopsis as above. Write all the code in single C file: 1. The program has its local clock mechanism. You must invoke startClock() when you are ready to service threads. The file reading should be performed before this. Once the startClock() is invoked, the getCurrentTime() can be invoked to see how much time units are passed since startClock() was invoked. This will provide a local clock ticks behavior to service your threads. 2. The thread information will be provided to this program in a text file. You must accept the name of this file as command line argument. In this file, there will be one thread information per line. Each thread information has three attributes provided in the order: thread_id;start_time; lifetime. It is not necessary that the individual thread lines are in any specific order.start_time indicates that at what time a thread should be created and started lifetime is the time units for which a thread must stay alive. Use the methods in step 1 in a suitable way to implement this functionality. 3. To read the file, readFile() function is provided. However, it has a small part missing that you must complete so that the thread attributes can be stored in memory in a suitable way. This also requires the completion of struct thread. Add suitable members to struct thread and the store the content of the file in a suitable data structure. 4. Once you have thread information in memory, start servicing the threads using the suitable POSIX library calls. main() is provided but you have to complete it in a suitable way. The program will keep running if there are some threads which are not yet created or if there are some running threads. 5. The threadRun() is the function that each thread must run. Implement this function so that each thread takes care of its lifetime and terminates when that is over. 6. The image below shows the expected output for the sample input file provided with this assignment: pscubuntu: cp386/a2$ .Assignment_1 samplez in.txt 111 Mew Thread with ID 118 is started. IZ1 Merw Thread uith ID t2 ix started 151 Mew Thread with ID ti is started 191 Thread with ID t2 is finished. [10] Thread with ID ti is finished. [16] Thread with ID tie is finished. (20) New Thread with ID t22 is started [25] Thread with ID t22 is finished. psc@ubuntu:cp386/a2$

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!