Question: os 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

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

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

os

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 New Text Document - Notepad File Edit Format View Help 3 1 1 2 2 3 13 4 1 5 26 Microsoft Visual Studio Debug Console thread : 1 is doing a computation the sum of numbers between 1 and 1000000 is : 1783293664 thread : 1 Worked : thread : 2 is doing a computation the sum of numbers between 1 and 1000000 is : 1783293664 thread : 2 Worked thread : 3 is doing a computation the sum of numbers between 1 and 1000000 is : 1783293664 thread : 3 Worked : C:\Users\Inferno source repos \assignment4\Debug assignment4.exe (process 16272) exited with code 0. 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!