HW#3: Dining Philosopher Problem

HW#3: Dining Philosopher Problem

<p>HW#3: Dining Philosopher Problem</p><p>Due: March 27 Later homework penalty= X * 5%, X is the delay in days.</p><p>C/C++ programmer: using pthread semaphore Java programmer: using java monitor</p><p>Description: You will implement a deadlock free solution for dining philosopher problem. Your main thread will ask how many philosophers are going to participate this fun experiment and the number of time he will eat (N). Each philosopher will be represented by one thread and has the following behavior:</p><p>Loop (N times){</p><p>LOG(“thread I hungry”); dp.pickup(i)</p><p>LOG(“thread I eating”);</p><p> eat…wait a random period of time…</p><p> dp.putdown(i)</p><p> wait a random period of time } Figure 1: Pi structure with monitor</p><p>All LOG information must be write in one log file.</p><p>Note 1 For Java programmer, the reference code is given in page 219. It is also scanned and posted on the website. </p><p>Note 2 The semaphore based solution in page 210 (fig 7.17) is simple, but it will generate deadlock. If your implementation is based on this method, you will get at most 50% points.</p><p>Note 3 For C/C++ programmer, since pthread don’t have monitor support, you will need to modify the reference code by using semaphore. Here is some hint to do this:  Use a mutex semaphore to guard the all call to pickup() and putdown()  Each condition variables can be replaced by a semaphore. The wait() and signal() call of a condition variable is replaced by wait(s) and signal (s) of that semaphore. A reference thread code structure will be like this:</p><p>Shared Semaphore mutex=1;</p><p>Loop (N times){</p><p>LOG(“thread I hungry”);</p><p>Wait(mutex); pickup(i) signal(mutex);</p><p>LOG(“thread I eating”);</p><p> eat…wait a random period of time…</p><p> wait(mutex) putdown(i) signal(mutex)</p><p> wait a random period of time } Figure 2: Pi structure using semaphore</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us