Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Lab on Semaphores in xv6

Semaphores

Semaphores

A semaphore specifies the maximum number of threads that can access a critical section simultaneously. A binary semaphore (max number of threads = 1) works the same as sleeplock. In this lab, we will implement read/write semaphore.

Complete and test your semaphore implementation. Submit your semaphore.c and a document showing your test outputs (with different number of processes) via Blackboard. The submission deadline is 8pm on Friday 17 September 2021. This lab will contribute 5% towards your overall course marks.

We will first create the implementation of semaphores in xv6. First, define an appropriate structure for semaphores. In the file semaphore.h provided with this lab, there is an empty structure called semaphore. Fill in the necessary ingredients that are needed to implement a semaphore.

Create a file semaphore.c that implements the following three functions:

// initsema - set the max threads

// and initialize whatever is needed

void initsema(struct semaphore *lk, int count)

  • downsema -
  • similar to acquiring lock,
  • but need to check how many processes are in there.
  • Return the number of remaining threads that can access int downsema(struct semaphore *lk)
  • upsema – similar to releasing the lock.
  • Return the number of remaining threads that can access int upsema(struct semaphore *lk)

Add these function prototypes to def.h.

Add the following system call to sysfile.c for testing your semaphore implementation.

#include “semaphore.h”

. . .

int

sys_sematest(void)

{

static struct semaphore lk;

int cmd, ret = 0;

if (argint(0, &cmd) < 0)

return -1;

switch (cmd) {

case 0: initsema(&lk, 5); ret = 5; break;

case 1: ret = downsema(&lk); break;

case 2: ret = upsema(&lk); break;

}

return ret;

}

Complete the process to include this system call in xv6.

Since xv6 does not have threads implemented, we will use processes to test the semaphore. A user program sematest.c has been provided for you that makes use of this system call to test your semaphore implementation. Edit the Makefile so that this program is compiled together with xv6.

Check that your implementation works correctly by testing with several different number of processes allowed in the semaphore.

support
Whatsapp
callback
sales
sales chat
Whatsapp
callback
sales chat
close