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
Write an ALP program for ARM Cortex M3/4 to perform the following(1) SVC is to be called from an application task running at Thread unprivileged mode.(2) Two parameters are passed to the handler via R1, R2.(3) If the SVC number is last 3 digits of your Student ID (0 to 255) or last 2 digits of your Student ID (if last 3-digits of Student ID > 255), then the addition of the data in R1, R2 should be performed and after that return and resume application task.(4) If the SVC number is not your Student ID (3 or 2 digits), then return and resume application task.Give suitable screen shots of the KEIL IDE-in debug mode to demonstrate the desired outputs. Ensure that the screenshot captures system time & day.Below Program can be used (basic skeleton)as below to perform the above conditions .        AREA RESET, CODE, READONLYin DCD 0x20000100,0x8000005D, 0,0,0,0,0,0,0,0,0,SVC_handler+1,0,0,0,0,0,0,0,0,0,0,0       ENTRY  MAIN    LDR R1,=0X20000200       MSR PSP,R1         MOV R0,#3…
At the moment, work is being done by a thread with the priority 30. If (a) it used up all of its time quantum, what would be its re-assigned priority? If b is correct, then I/O has been blocked.
What are the distinctions between a thread operating in user mode and a thread operating in the kernel mode? Is there a preferred species that we may choose from?
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