CSCI 4534 - Operating Systems

Assignment 3 Requirements

Process synchronization algorithms

[24 points; 12 per subtask] Consider in turn each of the following proposed solutions to the critical section problem for two processes. For each proposed solution, first determine whether it is a correct one; then, justify your answer in the following manner: The first proposed solution is listed below: The second proposed solution is listed below: [24 points; 12 per subtask] Consider in turn each of the following alternative implementations of a counting semaphore using a binary semaphore (refer to section 7.4.4 of the textbook for the original implementation). For each proposed alternative, first determine whether it is a correct one; then, justify your answer in the following manner: The first proposed alternative is listed below: The second proposed alternative is listed below:

Resource allocator

You are given an extensible simulator of a resource allocator in csci4534.allocator.MainSimulator. This simulator keeps track of a set of simulated processes and multi-instance resources, as processes and resources are created and terminated/deleted, and processes request and release resource instances. For example, after you complete this task,
allocate.bat BankersAllocator np np np np nr:2 nr:2 nr:1 a:0:1:2 a:2:1:1:2:1
 a:3:1:1 a:1:0:2 a:0:0:2 a:1:1:2 r:0:0:1 xp:0 a:1:1:2 xr:0
will perform the following simulation and report the following output:
  1. The simulator initializes the specified instance of the csci4534.allocator.Allocator interface, csci4534.allocator.BankersAllocator in this case, and reports its name. You will only implement this single allocator in this programming task, and you are given no other allocator implementation. This is why you cannot get the output in the following steps if you execute the above command-line before you complete this task.
    Allocator: csci4534.allocator.BankersAllocator
    
  2. We first create a new process. The simulator asks the allocator to create and return an instance of a class implementing the csci4534.allocator.Process interface; BankersAllocator creates an instance of the csci4534.allocator.BankersProcess class. The simulator then assigns an arbitrary internal integer ID to this instance, and reports it on the screen, presumably 0 in this case. When applicable, the process ID is supplied as the first argument to other operations.
    Creating process: 0
    
  3. We then create a second, a third, and a fourth process, and receive in response their IDs, presumably 1, 2, and 3 in this case.
    Creating process: 1
    Creating process: 2
    Creating process: 3
    
  4. We then create a new resource with 2 instances. The simulator asks the allocator to create and return an instance of a class implementing the csci4534.allocator.Resource interface; BankersAllocator creates an instance of the csci4534.allocator.BankersResource class. Do not be confused by the multiple but distinct meanings of the word instance here: there are instances of Java classes, and there are instances of resources managed by the allocator. In this case, the simulator asks the allocator to create a single Java object; that single object must implement Resource; that single object must also represent a resource that has two instances available for allocation initially (the number of instances is given to the allocator); the allocator produces a single Java object whose class is BankersResource. The simulator then assigns an arbitrary internal integer ID to this object, and reports it on the screen, presumably 0 in this case.
    Creating resource with 2 instances: 0
    
  5. We then create a second resource with 2 instances, and a third one with 1 instance, and receive in response their IDs, presumably 1 and 2 in this case.
    Creating resource with 2 instances: 1
    Creating resource with 1 instances: 2
    
  6. We then have process 0 request the allocation of 2 instances of resource 1. The simulator forwards the request to the allocator via a csci4534.allocator.Request object, which identifies the relevant process and resource(s) via the Process and Resource implementations the allocator created above; the allocator does not see the IDs used by the simulator. For each resource that is part of a request, a Request object contains a csci4534.allocator.ResourceCount object, pairing a Resource object with the number of requested resource instances.

    When the allocator processes the request, the simulator reports its response. In this case, the request is granted because the resource instances are available, and the allocation would not violate the allocator's fairness (a.k.a. no starvation) policy.

    Allocation request [0;(1,2)]: granted
    
  7. We then have processes 2 request (simultaneously) the allocation of 1 instance of resource 1 and of 1 instance of resource 2. This is a single request, which the simulator passes on to the allocator as a single unit. The allocator can either grant, enqueue, or reject (due to potential deadlock or invalid data; see below) the request as a whole, but never partially. Not enough instances of resource 1 are available (even though there are adequate instances of resource 2 available), so the allocator responds that the request has been enqueued, and the simulator reports this response. The queue of pending requests is maintained and wholly managed by the allocator, not by the simulator.
    Allocation request [2;(1,1)(2,1)]: enqueued
    
  8. We then have process 3 request the allocation of 1 instance of resource 1. The request is enqueued.
    Allocation request [3;(1,1)]: enqueued
    
  9. We then have process 1 request the allocation of 2 instances of resource 0. The request is granted.
    Allocation request [1;(0,2)]: granted
    
  10. We then have process 0 request the allocation of 2 instances of resource 0 as well. The request is enqueued.
    Allocation request [0;(0,2)]: enqueued
    
  11. We then have process 1 request the allocation of 2 instances of resource 1. The allocator throws an csci4534.allocator.AllocatorException, signifying that not only can't the request be granted, but it also can't be enqueued because doing so would immediately bring the system into a deadlocked state. The simulator simply displays the exception.
    Allocation request [1;(1,2)]: csci4534.allocator.AllocatorException:
     Deadlock will occur if process is enqueued
    
  12. We then attempt to have process 0 release its hold on 2 instances of resource 1; our intent is to simulate process 0 completing its use of those resources and making them available for process 1. The simulator forwards the request to the allocator via a Request instance; but the simulator calls a different method of the allocator than the one it calls for resource allocation. The allocator throws an AllocatorException, signifying that a process that has a pending request cannot take any direct de/allocation action. That is because such processes are in the waiting state, and do not receive CPU time to take further action. In other words, our attempt supplied an invalid input which the allocator recognized as such.
    Release [0;(1,2)]: csci4534.allocator.AllocatorException:
     Process has pending request
    
  13. We then attempt to delete/terminate process 0. The allocator accepts this command, and deletes process 0, removing any requests that process had pending. Also, since process 0 had received 2 instances of resource 1 in the past, they are both released.

    Now that resource instances have become available, some of the pending requests may be able to proceed. So the allocator may dequeue and grant pending requests from the queue, depending on its fairness policy. The allocator does this whenever resource instances become available, whether by process deletion (xp command) or successful resource release (r command). The simulator receives this list of granted requests, and displays them. In this case, process 2 receives 1 instance of resource 1, and 1 instance of resource 2; and process 3 receives 1 instance of resource 1.

    Deleting process 0: done
     Dequeued: [2;(1,1)(2,1)]
     Dequeued: [3;(1,1)]
    
  14. We now repeat our earlier request to have process 1 receive 2 instances of resource 1. The request is enqueued.
    Allocation request [1;(1,2)]: enqueued
    
  15. We then attempt to delete resource 0. The simulator forwards the command to the allocator who refuses to execute it, responding instead that the resource is in use (either active use, i.e. allocated to a process, or pending use, i.e. the allocator has a pending request for that resource). The allocator does so by throwing an AllocatorException. In other words, our attempt supplied an invalid input that the allocator recognized it as such. Resource 0 is not deleted. This is analogous to requesting Windows to delete a file currently open by some application, and being told that the operation cannot be completed.
    Deleting resource 0: csci4534.allocator.AllocatorException:
     The resource is in active use
    
  16. As this was out last simulated operation, the simulator displays the system state, and exits.
    Resources:
     ID: 0; Available: 0
     ID: 1; Available: 0
     ID: 2; Available: 0
    Processes:
     ID: 1; Allocations: (0,2)
     ID: 2; Allocations: (2,1)(1,1)
     ID: 3; Allocations: (1,1)
    Allocator request queue:
     [1;(1,2)]
    
Study Allocator, Process, and Resource (the three interfaces you have to implement), along with the rest of the provided code. For most classes, it might be convenient to read first the HTML documentation produced from the code's javadoc comments (by running jdoc.bat). The HTML documentation doesn't cover everything (e.g. it doesn't cover in-line comments or private methods), but it's more readable.

After you have finished studying the provided code, get ready to fill-in the provided stub classes with your allocator implementation. As you form your plan of attack, keep in mind the following:

Finally, carry out the implementation in the following steps:

[2 points] Implement csci4534.allocator.Vector.

[18 points] Compose a minimal implementation of the allocator in BankersAllocator and its helpers BankersProcess and BankersResource. Such an implementation maintains correctly the queue of pending requests, the list of active processes, the list of active resources, their respective allocations, etc. Also, all allocator methods are correctly implemented. For example, the release of a resource and the deletion of a process should trigger the granting of the proper pending requests. However, do not worry at this point about deadlocks, robustness, or fairness.

[20 points] Add deadlock detection to your implementation via the banker's algorithm variant of section 8.6.2 of your textbook.

[10 points] Improve your implementation to make it robust. It is critical that you make no assumptions regarding the arguments to your methods, except that no arguments will

Moreover, you can expect your allocator to be called by a single Java thread. But, for example, a method expecting a Process argument may receive null, or a process created by another allocator. Again, these are examples; it is up to you to determine the complete list of possible invalid inputs or invalid states you may encounter. Be sure to throw instances of AllocationException with a descriptive message whenever your allocator detects any misuse of its methods. Real OS resource allocators have to be extremely robust given their pivotal role in the reliable operation of a computer system.

[10 points] Add a fairness policy to your implementation. That is, a process that issues a pending request will not be forever bypassed by other processes which make later allocation requests for the same resource(s). Document your policy in detail with in-line comments. For a fairness policy to receive full marks, it should be not only fair, but it should also achieve good resource utilization: allowing a single allocation at a time across all processes and resources guarantees fairness but it's not at all efficient. Of course, its implementation should also be correct.

[1 point] How much time did you spend on this section?


[1 point] Summarize in a concise list the key concepts and/or technologies that this assignment helped you digest. You don't have to explain the listed items; just name them.
© 2004 Apostolos Lerios