Write a C/C++ program that uses the PTHREAD library to create 5 threads and MUTEXES to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a C/C++ program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them. The program must do the following: * The parant may initialize the mutexes, then call the 5 threads. Detach the threads once they are created. * Each thread will open its own command file (datal.in, data2.in, etc) for reading. The file format will be: R +/-N +/-N Note that there may be many +/-N lines W R indicates the start of a critical section the account balance from global storage. +/-N indicates a deposit (+N) or withdraw (-N) from the account. W indicates the end of the critical section where you will write the accout balance to global storage. At this point each thread must also display the text: Account balance after thread *thread_name_here* is $xxx NOTES: - - where you will acquire Start with a budget of 0 (zero). Each input file may be of different length and you may simply allow the thread to die at that point. Hence, the parent should NOT employ a pthread_join. REQUIREMENTS: The result of the single account should NOT contain any lost update. That is, the results should be the same as if a single thread processed all 5 input files on the single account (hint, for testing). However, you CANNOT force the threads into any serial execution. Once spawned they must be free from external influences (other than the mutexes). I suggest you include a sleep() function in each thread to make sure each thread runs long enough to get the random update behavior required. 1. Your program must run on the Linux Mint machines in Engineering. 2. Your full name must appear as a comment at the beginning of your program. 3. Your source code must be named hw4-yourname.c or hw4-yourname.cpp 4. Your source MUST compile using gcc or g++ in accordance with the extension. 5. Your program must only use mutex (s) for synchronization. No conditionals, no semaphores, no global variables. 6. Your program must use pthreads. Not threads. 7. Failure to follow 4 and 5 will result in -50% of the grade. Write a C/C++ program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them. The program must do the following: * The parant may initialize the mutexes, then call the 5 threads. Detach the threads once they are created. * Each thread will open its own command file (datal.in, data2.in, etc) for reading. The file format will be: R +/-N +/-N Note that there may be many +/-N lines W R indicates the start of a critical section the account balance from global storage. +/-N indicates a deposit (+N) or withdraw (-N) from the account. W indicates the end of the critical section where you will write the accout balance to global storage. At this point each thread must also display the text: Account balance after thread *thread_name_here* is $xxx NOTES: - - where you will acquire Start with a budget of 0 (zero). Each input file may be of different length and you may simply allow the thread to die at that point. Hence, the parent should NOT employ a pthread_join. REQUIREMENTS: The result of the single account should NOT contain any lost update. That is, the results should be the same as if a single thread processed all 5 input files on the single account (hint, for testing). However, you CANNOT force the threads into any serial execution. Once spawned they must be free from external influences (other than the mutexes). I suggest you include a sleep() function in each thread to make sure each thread runs long enough to get the random update behavior required. 1. Your program must run on the Linux Mint machines in Engineering. 2. Your full name must appear as a comment at the beginning of your program. 3. Your source code must be named hw4-yourname.c or hw4-yourname.cpp 4. Your source MUST compile using gcc or g++ in accordance with the extension. 5. Your program must only use mutex (s) for synchronization. No conditionals, no semaphores, no global variables. 6. Your program must use pthreads. Not threads. 7. Failure to follow 4 and 5 will result in -50% of the grade.
Expert Answer:
Answer rating: 100% (QA)
Below is a C program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them for the described task include include include ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Thurman Corp. charges its customers a 7% sales tax on all the goods it sells. At the time of sale, Thurman includes the combined sales and sales tax amount in the "Sales Revenue" account. Thurman...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The fixed budget for 21,300 units of production shows sales of $468,600; variable costs of $63,900; and fixed costs of $143,000. The company's actual sales were 26,300 units at $531,600. Actual...
-
The Eldorado Corporation's controller prepares adjusting entries only at the end of the fiscal year. The following adjusting entries were prepared on December 31, 2011: Additional information: 1. The...
-
The differential equation for small-amplitude vibrations y(x, t) of a simple beam is given by Where ρ = beam material density A = cross-sectional area I = area moment of inertia E = Youngs...
-
An analyst at Dawn Chemical notes that its cost of debt is far below that of equity. He concludes that it is important for the firm to maintain the ability to increase its borrowing because if it...
-
In a lifting machine, efforts required to lift loads of 250 N and 360 N were 65 N and 80N respectively. The velocity ratio of the machine is 25. Determine the law of the machine and the efficiency to...
-
Samuel C. Mazilly wrote a personal check that was drawn on Calcasieu- Marine National Bank of Lake Charles, Inc. (CMN Bank). The check was made payable to the order of Lee St. Mary and was delivered...
-
What types of interviewing styles are there, and which do prefer using? Have experienced a group interview? If so, explain how that went ? Have ever been part of any of these: stress interview, STAR...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Discuss the importance of literature review in conducting research.
-
Suppose you expect the price of BHM stock, which currently sells at at $40, to rise. You buy 300 shares by borrowing $4000 from your broker at the interest rate of 8% and funding the rest of the...
-
Standard Industry Classification codes (SIC) are used for financial statement "benchmarks" analysis. Your company's financial results would need to be compared to others. SICs provide the format to...
-
8. Consider the all-reduce operation in which each processor starts with an array of m words, and needs to get the global sum of the respective words in the array at each processor. This operation...
-
2) Design the PIC-based schematic circuit and Write a MikroC program that displays and repeats the sequence [3-5-7-A-L - P] on a common cathode 7-segment display connected to PORTB of the 18F452...
-
Packer, Inc., a U.S. producer of computer disks, plans to establish a subsidiary in Mexico in order to penetrate the Mexican market. Packer's executives believe that the Mexican peso's value is...
-
A 35-year-old man presents to the urgent care center with severe neck pain. The physician examines the patient and makes the diagnosis of cervical nerve impingement and injects an anesthetic agent...
-
What impact has the Internet had on the globalization of small firms? How do you think small companies will use the Internet for business in the future?
-
Teresa is a civil engineer who uses her automobile for business. Teresa drove her automobile a total of 21,732 miles during 2012, of which 95 percent was business mileage. The actual cost of...
-
Sally hires a maid to work in her home for $250 per month. The maid is 25 years old and not related to Sally. During 2012, the maid worked 10 months for Sally. a. What is the amount of Social...
-
Professor Patricia (Patty) Pate is retired from the PalmSprings Culinary Arts Academy (PSCAA). She is a single taxpayer and is 68 years old. Patty lives at 98 Colander Street, Henderson, NV 89052....
-
Consider the situation illustrated in Figure 25. 11. A positively charged particle is lifted against the uniform electric field of a negatively charged plate. Ignoring any gravitational interactions,...
-
A positively charged particle is moved from point A to point B in the electric field of the massive, stationary, positively charged object in Figure 25. 12. (a) Is the electrostatic work done on the...
-
Figure 25. 13 shows both the electric field lines and the equipotentials associated with the given charge distribution. (a) Is the potential at point A higher than, lower than, or the same as the...
Study smarter with the SolutionInn App