Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(urgent) pls check down below under the question for the sample input and output provided. pls read the question carefully. thank you. Create a C

(urgent)

pls check down below under the question for the sample input and output provided. pls read the question carefully. thank you.

Create a C program that creates five threads. the program should be able to take different inputs. ( pls use the sample input provided to test the code and make sure the output is similar to the sample output provided ). In the main function of your program, the number of lines of the input should be calculated and it should be decided how many lines each thread should read. For example, if the input contains 10 lines and there are 5 threads, the threads must read 2 lines at a time. When this value is fractional, the value should be rounded up. For example, if a 14-line input is being read and the number of threads at hand is assumed to be 5, 3 lines will be read in each thread operation. At the end of the line, the relevant thread should read 2 lines instead of 3 and return the result. Each thread will return its own sums after line reading and calculation, and print the total value to the screen. Since your input file and the global variable to hold the total result are shared, you need to set the access settings (you should use semaphore). It is not necessary for the threads to run sequentially. But each thread must be involved in the process and read from the file. The sample input file and program output should be as follows.

sample input:

1.23 2.66 3.45 81.23 9.11 3.33 7.78 4.12 1.11 2.22

sample output:

Thread 1 reads 1. line. The value is 1.23 Thread 1 reads 2. line. The value is 2.66 Shared Resource: 3.89 Thread 2 reads 3. line. The value is 3.45 Thread 2 reads 4. line. The value is 81.23 Shared Resource: 88.57 Thread 3 reads 5. line. The value is 9.11 Thread 3 reads 6. line. The value is 3.33 Shared Resource: 101.01 Thread 4 reads 7. line. The value is 7.78 Thread 4 reads 8. line. The value is 4.12 Shared Resource: 112.91 Thread 5 reads 9. line. The value is 1.11 Thread 5 reads 10. line. The value is 2.22 Shared Resource: 116.24

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

Students also viewed these Databases questions