Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that both threads are hitting the upper and lower bounds (50 and 0 respectively) at the same time. Both examples below highlight the deadlock.</p> <p>Scenario 1</p> <ol> <li>request(29) - freePages=21</li> <li>request(30) - under 0 so waits</li> <li>release(30) - over 50 so waits : deadlock</li> </ol> <p>Scenario 2</p> <ol> <li>request(29) - freePages=21</li> <li>release(30) - over 50 so waits</li> <li>request(30) - under 0 so waits : deadlock</li> </ol> <p>I am not sure what the exact requirements are for the homework problem but you need to revisit the release and request methods. I see two viable solutions:</p> <ol> <li>Change the release method so that it only releases up to MAX_FREE but will still return</li> <li>Change the release method so that it can release a subset of the amount requested, notifyAll, reenter the wait so it can release the remaining amount.</li> </ol> <p>Also, you are kind of using the ExecutionService wrong. The ExecutionService is what creates the Threads so there is no reason for you to create the threads like you are doing.</p> <pre><code>Thread t1 = new Thread(new MemAllocRequester(memoryAllocator)); Thread t2 = new Thread(new MemAllocReleaser(memoryAllocator)); </code></pre> <p>The threads you are creating will actually never be 'started' as Threads. It is still working for you because the ExecutionService threads will call your Thread.run() which will call MemAlloc*.run(). i.e. your t1 and t2 threads just pass the run() call along and provide no value.</p> <p>Your MemAllocRequester and MemAllocReleaser are Runnables so just pass those into the ExecutionService directly.</p> <pre><code>executor.submit(new MemAllocRequester(memoryAllocator)); executor.submit(new MemAllocReleaser(memoryAllocator)); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload