Computer Systems: Program... -Access
Computer Systems: Program... -Access
3rd Edition
ISBN: 9780134071923
Author: Bryant
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
The following page table is for a system with 16-bit virtual and physical addresses and with 4,096-byte pages. The reference bit is set to 1 when the page has been referenced. Periodically, a thread zeroes out all values of the reference bit. A dash for a page frame indicates the page is not in memory. The page-replacement algorithm is localized LRU, and all numbers are provided in decimal.   Page Page Frame Reference Bit 0 7 0 1 − 0 2 14 0 3 13 0 4 15 0 5 8 0 6 0 0 7 − 0 8 4 0 9 5 0 10 − 0 11 1 0 12 9 0 13 3 0 14 − 0 15 2 0 Convert the following virtual addresses (in hexadecimal) to the equivalent physical addresses. You may provide answers in either hexadecimal or decimal. Also set the reference bit for the appropriate entry in the page table. 0xE13C 0x5A97 0x59D8 0x1002 0xCCB1 Using the above addresses as a guide, provide an example of a…
Discuss different thread synchronization mechanisms in multithreading, such as locks, semaphores, and barriers. Provide examples of scenarios where each mechanism is best suited.
The following page table is for a system with 16-bit virtual and physical addresses and with 4,096-byte pages. The reference bit is set to 1 when the page has been referenced. Periodically, a thread zeroes out all values of the reference bit. A dash for a page frame indicates the page is not in memory. The page-replacement algorithm is localized LRU, and all numbers are provided in decimal. Page Page Frame Reference Bit 0 7 0 1 15 0 2 10 0 3 13 0 4 14 0 5 -- 0 6 5 0 7 0 0 8 -- 0 9 9 0 10 1 0 11 11 0 12 2 0 13 − 0 14 3 0 15 8 0   Convert the following virtual addresses (in hexadecimal) to the equivalent physical addresses. You may provide answers in either hexadecimal or decimal.  Show the calculation steps Also set the reference bit for the appropriate entry in the page table. 0xD551 0x8D17 0x33E2
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education