Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to be written in C Three salesmen come to a manufacturer to get some T-shirts to sell on the market. The total number of

Need to be written in C  Three salesmen come to a manufacturer to get some T-shirts to sell on the market. The total number of T-shirts is 1000. Saleman A each time takes 1/3 of the remaining T-shirts. B takes 1/4 of the remaining T-shirts and C takes 1/5 of the remaining. If the number of T-shirts for a saleman to take is not an integer, round it up to the ceiling integer. For example, if the result is 3.14, round it up to 4. Use three threads to simulate this. Each thread should execute in a loop. When the T-shirts are gone, stop all threads and terminate the program. Print out the T-shirts taken by each salesman each time. In the end, you add up all the T-shirts given out. If the total does not come up to 1000, your program is wrong. a. Write a program without considering the mutual exclusion. Run the program several times to show that mutual exclusion is not guaranteed and the result is not correct. b. Write the program again considering the mutual exclusion. Run the program several times to show that mutual exclusion is guaranteed. To make longer execution of threads, use some sleep(n) functions in the program. Experiment with n to choose the best one to show the results. The output may look like this (yours maybe different): A takes away 334 T-shirts. B takes away 167 T-shirts. C takes away 100 T-shirts. B takes away 100 T-shirts. .... The total number of T-shirts given out is: ... 

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

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions