Question: Use your code from p 1 . c and implement a timer which will count how many seconds each thread has taken. Print out the

Use your code from p1.c and implement a timer which will count how many seconds each thread has taken. Print out the following:
1. Thread 1 duration (1 Marks)
2. Thread 2 duration (1 Marks)
3. Total duration (how long it takes both process to complete)(1 Marks)
4. Average time taken for a process to complete (1 Marks)
In addition, modify the code to use IPC share memory(pointers) to pass a long variable from the parent to child process and print it in the child process.
1. For Thread 1 pass and print the number 1.(3 Marks)
2. For Thread 2 pass and print the number 2.(3 Marks)
Expected Output:
Shared memory Thread1 value: 1
Shared memory Thread2 value: 2
thread1 took 0.000075 seconds to execute
thread2 took 1.533661 seconds to execute
thread1 and thread2 took 1.533661 seconds to execute
average time taken was 0.766830

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 Programming Questions!