Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
bartleby

Concept explainers

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

Explanation of Solution

Given C code:

//Include libraries

#include "csapp.h"

#include "sbuf.h"

#include<pthread.h>

#define NTHREADS 4

#define SBUFSIZE 16

//Declare variable

static int byte_cnt;

//Declare variable

static sem_t mutex;

//Define method init_echo_cnt

static void init_echo_cnt(void)

{

//Call method

Sem_init(&mutex, 0, 1);

//Assign value

byte_cnt = 0;

}

//Define method echo_cnt

void echo_cnt(int connfd)

{

//Declare variable

int n;

//Declare array

char buf[MAXLINE];

//Create instance

rio_t rio;

//Assign value

static pthread_once_t once = PTHREAD_ONCE_INIT;

//Call method

pthread_once(&once, init_echo_cnt);

//Call method

Rio_readinitb(&rio, connfd);

//Loop

while((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0)

{

//Decrement

P(&mutex);

//Update value

byte_cnt += n;

//Display message

printf("server received %d (%d total) bytes on fd %d\n", n, byte_cnt, connfd...

Blurred answer
Students have asked these similar questions
What did you find most interesting or surprising about the scientist Lavoiser?
1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0
Analyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related.   Refer to the raw data (table):
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science 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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781305971776
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning