Question: Question 1 : Read - Write Semaphore ( Max Mark: 3 0 / 1 0 0 ) This question requires you to implement Read -

Question 1: Read-Write Semaphore (Max Mark: 30/100) This question requires you to implement Read-Write semaphores for xv6. Two files semaphore.h and semaphore.c are provided for you as a reference design for semaphore implementation in xv6. A structure representing a semaphore is defined in semaphore.h. There are three functions associated with the semaphore initsema(), downsema() and upsema(), that initialize, decrement and increment a semaphore respectively. The code for these functions is provided in semaphore.c. Study them in conjunction with the lecture slides to make sure you understand them. You may want to compile them with the xv6 kernel and see how it works with the user program sematest.c provided for you. In order to do so, add the function provided in sys_sematest.c to sysfile.c and make sematest() a system call for xv6 in the usual way. Then compile xv6 with make qemu CPUS=1 and run sematest. Running xv6 on a single CPU prevents the displayed messages from being garbled. Task: Implement Read-Write Semaphore that can be used to solve the Reader/Writer problem as discussed in class. In semaphore.h there is already an empty struct rwsemaphore. There are also five associated function prototypes: void initrwsema(struct rwsemaphore *rws); int downreadsema(struct rwsemaphore *rws); int upreadsems(struct rwsemaphore *rws); void downwritesema(struct rwsemaphore *rws); void upwritesema(struct rwsemaphore *rws); You will need to design an appropriate struct rwsemaphore, and implement these five functions in semaphore.c. Your struct rwsemaphore should be defined using the semaphore in semaphore.c. That is, do not use the xv6 locks. Note 2024 AUT 2 that you do not need to wake up the waiting threads/processes in the same order as semaphores are requested. There is a function called sys_rwsematest() in sys_sematest.c. Make rwsematest() a system call like sematest() above. A user test program has been provided in rwsematest.c. It makes use of this system call. The test program conducts three tests read lock test, write lock test, and read & write lock test. You will need to work out from this program what the correct output of each test should be. Capture your test output and paste it into a document. Then explain why this output shows that your implementation is correct.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!