Question: Write a multi-threaded application in which there are three threads. All threads open the same file. The content of this file is assumed to be

 Write a multi-threaded application in which there are three threads. All

threads open the same file. The content of this file is assumed

Write a multi-threaded application in which there are three threads. All threads open the same file. The content of this file is assumed to be lines that each consist of two numbers (you can start by a file that contain the line "O 0"). The first number in each line is the id of the thread that wrote the second number. Each thread performs the following steps: Open the file. Reads the last line in the file Close the file. Increment the second number in the last line by 1. Perform some computation such as finding the sum of the numbers between 1 and 1000000. Open the file. Write the thread id and the incremented number to the end of the file. Close the file. Note that: at the end, all numbers (second number in each line) that are written to the file by all threads should be in sequence. Also, you should figure out what the critical region is, and to prevent the race condition, write your own code using: a. Mutex lock synchronization tool b. Semaphore synchronization tool Naw Text Document - Notepad File Edit Format Vier Felp. 0 0 3 1 12 21-3 Type here to search o per ; 49F Light rain 5 2 thread : i is doing a computation the sum of numbers between 1 and 1002890 is : 178329386 thread : I korked thread : 2 is daing a computation the sum of murders between 1 and 1990eaa is : 1783293664 thread : 2 korked thread : 3 is doing a computation the sum of numbers between 1 and 1eeeee is : 1783299664 thread : 3 worked C:\Users\Inferno source reposlassignment4\debug\ussignment4.exe (process 16272) exited with code e. press any key to close this window

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!