Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write it in c++ language please Write a multi-threaded application in which there are three threads. All threads open the same file. The content of

write it in c++ language please
image text in transcribed
image text in transcribed
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 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 : 1783 293664 thread : 3 Worked C:\Users\Inferno source eposlassignment4\Debug\assignment4.exe (process 16272) exited with code e. Press any key to close this window 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 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 : 1783 293664 thread : 3 Worked C:\Users\Inferno source eposlassignment4\Debug\assignment4.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

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

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions

Question

Identify how culture affects appropriate leadership behavior

Answered: 1 week ago