The Bear and the Honeybees. There are n honeybees and a bear. They share a pot o
ID: 3811307 • Letter: T
Question
The Bear and the Honeybees. There are n honeybees and a bear. They share a pot of honey. the pot is initially empty; its capacity is H equal-portions of honey. the bear sleeps until the pot is full, then eat the entire pot of honey and goes back to sleep. Each bee repeatedly gathers one portion of honey and puts it in the pot; the bee that fills the pot awakens the bear. Note that while the bear is eating honey, no honeybees can add any honey to the pot. Represent the bear and honeybees as processes and develop pseudo-code that simulates the actions of the bear and honeybees. Use semaphores for synchronization. Show the declarations and initial values of all semaphores that you use (e.g. semaphore mutes = 1). In your pseudocode uses seem Wait and see Signal operations to operate semaphores (e.g. seem. Wait (seem) or seem Signal (seem)). global variables declarations void bear(void) {} void honeybee(void) {Explanation / Answer
This seems to be a problem of mutual exclusion as only one can enter the pot either the bear or honeybee.
So, the form of process should be like:
entry_protocol:
wait(semaphore)
exit_protocol:
signal(semaphore)
And both the protocols should be used for both honeybee and bear at same time.So, we can use here semaphore with initial value as 1.
semaphore =1 as only one can share the pot at one time.
for wait(semaphore)
if (semaphore > 0) then
semaphore := semaphore - 1
else
block process on semaphore //block access to one who entered and exit
for signal(semaphore)
if processes are blocked on semaphore then
unblock one of them //bear or honeybee
else
semaphore := semaphore + 1 //provide access to waiting one
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.