Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone please help me asap on this code using c code and using the semaphore function. Please dont copy the incorrect answer as i

Can anyone please help me asap on this code using c code and using the semaphore function. Please dont copy the incorrect answer as i have lost many questions getting wrong answer. Please help me its very urgent.

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 congured to only read a message when it is ready and how the producer can be congured 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 dierence 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.

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

Students also viewed these Databases questions

Question

$1.60. $4.45. $.94. $3.98 $5.49. $1.60. $4.45. $.94. $3.98 $5.49

Answered: 1 week ago

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago