Starting from:
$35

$29

Assignment 3 Solution

There are two problems in this assignment.




This is also a group assignment. You’ll work with the same group that you worked in Assignment2. If you want to change your group, please let me know.







Problem-1: Producer-Consumer










In computing, the producer–consumer problem is a classic example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, which share a common, fixed-size data buffer/queue.




 
The producer’s job is to generate data, put it into the queue, and start again.




 
At the same time, the consumer is consuming the data (i.e. removing it from the queue), one piece at a time.




Problem: Using locks and condition variable, we need to make sure that the producer won’t try to add data into buffer if it’s full and that the consumer won’t try to remove data from an empty data buffer. You are given the implementations for the following Java files already:




 
App.java




 
Producer.java




 
Consumer.java




You are asked to provide the producer-consumer implementation for SharedDataStore.java using locks and condition variables.




Sample Run









//App.java




public class App {




public static void main(String[] args) {




SharedDataStore dataStore = new SharedDataStore(5);//max capacity Producer producer = new Producer(dataStore);




Consumer consumer = new Consumer(dataStore);

producer.start();




consumer.start();




}




}




//Producer.java




public class Producer extends Thread{ private SharedDataStore dataStore;



public Producer(SharedDataStore dataStore) { this.dataStore = dataStore;

}




@Override




public void run() {

while(true){




Random r = new Random();

int number = r.nextInt(10);




dataStore.produce(number);




}

}




}




//Consumer.java




public class Consumer extends Thread{ private SharedDataStore dataStore;




public Consumer(SharedDataStore dataStore) { this.dataStore = dataStore;




}




@Override




public void run() {




while(true){

dataStore.consume();




}




}




}















//SharedDataStore.java




public class SharedDataStore {




//TODO: your code goes here
















Problem 2: Implement Locks in os/161




OS/161 is an incomplete operating system. Locks are not implemented in OS/161. In this assignment, you are asked to implement the locks for OS/161. The interface for the lock structure is defined in kern/include/synch.h. Implementation for functions is provided in kern/threads/synch.c. You can use the implementation of semaphores as a model, but do not build your lock implementation on top of semaphores or you will be penalized. In other words, your lock implementation should not use sem_create(), P(), V() or any of the other functions from the semaphore interface. OS/161 also includes test cases for locks.




You are going to complete the implementation for the following lock functions. In class, while we were using pthread API, we called create, lock, unlock, ... functions of thread API. In this assignment, you’ll have the opportunity to write the logic behind these low level functions in OS/161. I hope you’ll enjoy it!











In order to test you implementation, uou are required to run test, lt1 which provided by sys161. You should be receiving “Success” as the result of the test. A sample screenshot for running the test is given below.








What to Submit:




 
You are asked to submit your work as a single zip file via CANVAS. Zip file will include two folders

o Problem1: includes your work as an eclipse Java project. Please don’t forget to put comments in your source code explaining your reasoning for the solution. o Problem2: includes the kernel code that you updated (only the source files that




you updated), and a document with an explanation for your implementation and with sample screenshots showing success from test-runs using OS/161.












6

More products