Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 5: Implement semaphores (30 marks) Copy your code from Task 4 into a new directory named task5. Stage 1 Replace the use of busy

Task 5: Implement semaphores (30 marks) Copy your code from Task 4 into a new directory named task5. Stage 1 Replace the use of busy waiting with semaphores to achieve mutual exclusion and synchronise message passing between the producer and consumer. As with Task 1, you will need to research the Linux system calls necessary to accomplish this. The semget function is a good starting point. Your producer should now initially sleep for 1 second (1000 ms) between writing messages. Continue adjusting the sleep interval based on the message content as described in Task 4. Sleep intervals less than 800 ms are now valid. A value of 0 ms indicates the producer should not sleep between writing messages to the shared memory segment. You will need to consider how the consumer can be configured to only read a message when it is ready and how the producer can be configured to not overwrite a message before the consumer has had chance to read it. Stage 2 As before, use top to observe the utilisation of the producer and consumer for a variety of producer sleep intervals (as controlled by the message content). Does the implementation of semaphores make a difference to utilisation? Discuss your observations in your report and compare with previous tasks results. Hint: Think about how many semaphores you would need to achieve mutual exclusion and synchronisation between the producer and consumer. Refer back to the concurrency lecture material from week 4 if you need to refresh your memory on these concepts.

Note: Please dont ask task 4 code as i dont have task 4 code and please write the code in C

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

Are robots going to displace all workers? Explain your answer.

Answered: 1 week ago