Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

William Faulkner (the author) states that a writer needs three things: experienc

ID: 3683176 • Letter: W

Question

William Faulkner (the author) states that a writer needs three things: experience, observation, and imagination. Suppose that three threads are implementing automated authoring, but each has a knowledge base of only one of the three elements. Another three threads produce knowledge on two of the elements at a time. Given the semaphore state defined below and the individual thread implementations, identify why this solution fails and suggest a solution.

Setup Defs

inputSem = Semaphore(1)
experience = Semaphore(0)
observation = Semaphore(0)
imagination = Semaphore(0)

Input Thread 1

inputSem.wait()
experience.signal()
observation.signal()

Input Thread 2

inputSem.wait()
experience.signal()
imagination.signal()

Input Thread 3

inputSem.wait()
observation.signal()
imagination.signal()

Author Thread 1

experience.wait()
observation.wait()
inputSem.signal()

Author Thread 2

experience.wait()
imagination.wait()
inputSem.signal()

Author Thread 3

observation.wait()
imagination.wait()
inputSem.signal()

Explanation / Answer

This solution fails because another three threads produce knowledge on only the two elements .As a result a third element is always left behind.This will create an interference in the delay and the third element of one thread is not being allowed to wait and we are creating another thread 2 and repeating the same.Due to the interference and not letting of the third element to be waited for accepting a signal ,the abovesultion will fail.The right solution is to produce knowledge on all the three elements before another trhead can execute. This can happen in the following way:

Author Thread 1

experience.wait()
observation.wait()

imagination.wait()
inputSem.signal()

inputSem.signal()

Author Thread 2

experience.wait()

observation.wait()
imagination.wait()
inputSem.signal()

This shows all of them have to wait before an input is taken by a thread.This is the correct way to implement this above solutiion

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote