EBK COMPUTER SYSTEMS
EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 12, Problem 12.38HW

Explanation of Solution

Implementation of a concurrent prethreaded version of the TINY web server:

Modified code for “sbuf.h” file:

The modified code for “sbuf.h” from section 12.5.4 in book is given below:

#ifndef SBUF_HEADER

#define SBUF_HEADER

#include "csapp.h"

typedef struct

{

int *buf;          /* Buffer array */

int n;             /* Maximum number of slots */

int front;         /* buf[(front+1)%n] is first item */

int rear;          /* buf[rear%n] is last item */

sem_t mutex;       /* Protects accesses to buf */

sem_t slots;       /* Counts available slots */

sem_t items;       /* Counts available items */

} sbuf_t;

//Function declaration

void sbuf_init(sbuf_t *sp, int n);

void sbuf_deinit(sbuf_t *sp);

void sbuf_insert(sbuf_t *sp, int item);

int sbuf_remove(sbuf_t *sp);

//Function declaration for sbuf_empty

int sbuf_empty(sbuf_t *sp);

//Function declaration for sbuf_full

int sbuf_full(sbuf_t *sp);

#endif

Modified code for “sbuf.c” file:

The modified code for “sbuf.c” from section 12.5.4 in book is given below:

#include "csapp.h"

#include "sbuf.h"

/* Create an empty, bounded, shared FIFO buffer with n slots */

void sbuf_init(sbuf_t *sp, int n)

{

  sp->buf = Calloc(n, sizeof(int));

  sp->n = n;                       /* Buffer holds max of n items */

  sp->front = sp->rear = 0;        /* Empty buffer if front == rear */

  Sem_init(&sp->mutex, 0, 1);      /* Binary semaphore for locking */

  Sem_init(&sp->slots, 0, n);      /* Initially, buf has n empty slots */

  Sem_init(&sp->items, 0, 0);      /* Initially, buf has zero data items */

}

/* Clean up buffer sp */

void sbuf_deinit(sbuf_t *sp)

{

  Free(sp->buf);

}

/* Insert item onto the rear of shared buffer sp */

void sbuf_insert(sbuf_t *sp, int item)

{

  P(&sp->slots);                          /* Wait for available slot */

  P(&sp->mutex);                          /* Lock the buffer */

  sp->buf[(++sp->rear)%(sp->n)] = item;   /* Insert the item */

  V(&sp->mutex);                          /* Unlock the buffer */

  V(&sp->items);                          /* Announce available item */

}

/* Remove and return the first item from buffer sp */

int sbuf_remove(sbuf_t *sp)

{

int item;

  P(&sp->items);                          /* Wait for available item */

  P(&sp->mutex);                          /* Lock the buffer */

  item = sp->buf[(++sp->front)%(sp->n)];  /* Remove the item */

  V(&sp->mutex);                          /* Unlock the buffer */

  V(&sp->slots);                          /* Announce available slot */

return item;

}

//Function definition for empty buffer

int sbuf_empty(sbuf_t *sp)

{

//Declare variable

int ne;

//For lock the buffer

  P(&sp->mutex);                        

  ne = sp->front == sp->rear;

//For lock the buffer

  V(&sp->mutex);                         

return ne;

}

//Function definition for full buffer

int sbuf_full(sbuf_t *sp)

{

//Declare variable

int fn;

//For lock the buffer

  P(&sp->mutex);                        

  fn = (sp->rear - sp->front) == sp->n;

//For lock the buffer

  V(&sp->mutex);                        

return fn;

}

For code “tiny.c” and “tiny.h”:

Same code as section 11.6 in book.

sample.html:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>Home</title>

</head>

<body>

Tiny server Example

</body>

</html>

main.c:

#include <stdio.h>

#include "csapp.h"

#include "tiny.h"

#include "sbuf...

Blurred answer
Students have asked these similar questions
Hi-Volt Components You are the IT manager at Hi-Voltage Components, a medium-sized firm that makes specialized circuit boards. Hi-Voltage's largest customer, Green Industries, recently installed a computerized purchasing sys- tem. If Hi-Voltage connects to the purchasing system, Green Industries will be able to submit purchase orders electronically. Although Hi-Voltage has a computerized accounting system, that system is not capable of handling EDI. Tasks 1. What options does Hi-Voltage have for developing a system to connect with Green Industries' pur- chasing system? 2. What terms or concepts describe the proposed computer-to-computer relationship between Hi-Voltage and Green Industries? why not? 3. Would Hi-Voltage's proposed new system be a transaction processing system? Why or 4. Before Hi-Voltage makes a final decision, should the company consider an ERP system? Why or why not?
Consider the following expression in C: a/b > 0 && b/a > 0.What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to design a language in which this expression is guaranteed to evaluate to false when either a or b (but not both) is zero? Explain your answer
Consider the following expression in C: a/b > 0 && b/a > 0. What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to design a language in which this expression is guaranteed to evaluate to false when either a or b (but not both) is zero? Explain your answer.
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:9781337569798
Author:ECKERT
Publisher:CENGAGE L