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
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 12.4, Problem 12.6PP
A.
Explanation of Solution
Analysis from given section:
For variable instance “ptr”:
- For main thread:
- From the given code, the variable “ptr” is a global variable.
- It is written by the main thread.
- For peer thread 0 and thread 1:
- The variable “ptr” is read by the peer threads.
For variable instance “cnt”:
- For main thread:
- From the given code, the variable “cnt” is a static variable and it is contains with only one instance in memory. Hence, it is not exist in the main thread.
- For peer thread 0 and thread 1:
- The variable “cnt” is read and written by the peer threads.
For variable instance “i.m”:
- For main thread:
- From the given code, the variable “i.m” is a local automatic variable.
- It is stored on the stack of the main thread. Hence, this variable is exist in the main thread.
- For peer thread 0 and thread 1:
- The given variable is stored on the main thread, while its corresponding value is passed to the peer threads, the peer threads never place it on the stack. So, it is not shared.
For variable instance “msgs.m”:
- For main thread:
- From the given code, the variable “msgs.m” is a local automatic variable.
- It is stored on the stack of the main thread. Hence, it is exist in the main thread.
- For peer thread 0 and thread 1:
- The given variable is stored on the main thread...
B.
Explanation of Solution
Analysis of shared variable from part A:
From the part A, the variables “ptr”,...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I need answer question pls
Project Operations
Write a JAVA program that will maintain a phone directory using a Linked-List. The program should be able to perform the following operations: 1) Add persons details (first name, last name, phone number, city, address, sex and email) to the phone directory, where phone numbers in the directory have to be unique. (Note: each person record will store in one node in the linked-list and insert each person to the last) 2) Delete any person details by a given phone number. 3) Update telephone number by providing person first name. 4) Display all details of persons from a phone directory. 5) Search telephone number based on person first name. (Note: use sequential search to find all telephones for the given first name) 6) Sort all persons in the phone directory ascending based on person first name. (Note: use bubble or selection sort to arrange the entire phone directory)
Project Outputs The output has to display a menu of choices. Then the…
Complete the following code. The goal is to implement the producer-consumer problem. You are expected to extend the provided C code to synchronize the thread operations consumer() and producer() such that an underflow and overflow of the queue is prevented. You are not allowed to change the code for implementing the queue operations, that is the code between lines 25 and 126 as shown in the Figure below. You must complete the missing parts between lines 226-261 as shown in the screenshot.
Use C++ Programming Language.
Objective
Define a circular buffer data structure and test it.
Problem Description:
A circular buffer (also called a circular queue) is circular list of nodes where data items are added on one end of the buffer and removed from the other end. Because the nodes form a circular list, the list has no end or beginning: the tail node points to the head node, creating a ring of nodes. You may think of the nodes as containers or slots that are all initially empty but can be assigned a value in their data field info. Every time a new data item is inserted (inserting to a buffer is often referred as Writing), one slot is filled and the buffer has one less empty slot. Every time a data item is removed (referred to as Reading), the buffer has one more empty slot. Since the list has no beginning and no end, a pointer (writeIndex) is used to mark the next empty slot to write to and a second pointer (readIndex) is used to mark the next node to read from. The…
Chapter 12 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 12.1 - Prob. 12.1PPCh. 12.1 - Prob. 12.2PPCh. 12.2 - Practice Problem 12.3 (solution page 1036) In...Ch. 12.2 - Practice Problem 12.4 (solution page 1036) In the...Ch. 12.4 - Prob. 12.5PPCh. 12.4 - Prob. 12.6PPCh. 12.5 - Prob. 12.7PPCh. 12.5 - Prob. 12.8PPCh. 12.5 - Prob. 12.9PPCh. 12.5 - Prob. 12.10PP
Ch. 12.6 - Prob. 12.11PPCh. 12.7 - Prob. 12.12PPCh. 12.7 - Prob. 12.13PPCh. 12.7 - Prob. 12.14PPCh. 12.7 - Prob. 12.15PPCh. 12 - Prob. 12.20HWCh. 12 - Derive a solution to the second readers-writers...Ch. 12 - Prob. 12.22HWCh. 12 - Prob. 12.23HWCh. 12 - Prob. 12.24HWCh. 12 - Prob. 12.25HWCh. 12 - Prob. 12.26HWCh. 12 - Some network programming texts suggest the...Ch. 12 - Prob. 12.28HWCh. 12 - Prob. 12.29HWCh. 12 - Prob. 12.30HWCh. 12 - Implement a version of the standard I/O fgets...Ch. 12 - Prob. 12.32HWCh. 12 - Prob. 12.33HWCh. 12 - Prob. 12.34HWCh. 12 - Prob. 12.35HWCh. 12 - Prob. 12.36HWCh. 12 - Prob. 12.37HWCh. 12 - Prob. 12.38HWCh. 12 - Prob. 12.39HW
Knowledge Booster
Similar questions
- Task (C Language) Your task is to modify the scheduler in Project 8 so the jobs with higher priority are added before the jobs with lower priority. You will make the following change to the program: Modify the add_job function such that instead of adding to the end of the linked list, a job is added to an ordered linked list. A new job is added to an ordered linked list by priority. Jobs with higher priority are added before the jobs with lower priority. The list remains ordered by priority after the new job is added. If a new job has the same priority as other jobs, the new job will be added as the last one of the same priority. Example picture attached belowarrow_forwardQ3. (IN YOUR ANSWER FOR THIS QUESTION, PLEASE USE THE GRAPHICAL NOTATION GIVEN IN THE TEXTBOOK (Introduction to Computer Theory, by Cohen) WHILE DRAWING THE PDA, PDA's CONSTRUCTED USING OTHER NOTATIONS WILL NOT BE EVALUATED.) L3 is the language L3={a"bc")*d* | n>1, k21} over the alphabet E={a,b,c,d}. a) Build a one-stack Push Down Automata (PDA) to accept the language L3. Please explain your design shortly and draw the PDA. b) Build a multi-stack Push Down Automata (PDA) (for example with two stacks) to accept L3. Please explain your design shortly and draw the PDA.arrow_forwardJava programming question Please help me with C 7.31:arrow_forward
- Complete the following code. The goal is to implement the producer-consumer problem. You are expected to extend the provided C code to synchronize the thread operations consumer() and producer() such that an underflow and overflow of the queue is prevented. You are not allowed to change the code for implementing the queue operations, that is the code between lines 25 and 126 as shown in the screenshot. You must complete the missing parts as shown in the screenshot as well as complete the missing codes of producer and consumer. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <time.h> #include <pthread.h> #include <semaphore.h> #include <errno.h> #include <fcntl.h> #define MAX_LENGTH_CAP 100 #define INIT -127 #define UNDERFLOW (0x80 + 0x02) #define OVERFLOW 0x80 + 0x01 #define BADPTR (0x80 + 0x03) #define CONSUMER_TERMINATION_PROBABILITY 40 #define PRODUCER_TERMINATION_PROBABILITY 30 // ============= LOCKED…arrow_forwardProblem 1.2 Write a program that opens a text file ("input.txt") and reads its contents. Then using a stack it reverses the lines of the file and saves them into another file ("output.txt"). Make sure to include running and space complexity for your code. • Hint: use System.IO.File.WriteAlILines and System.IO.File.ReadAllLines, Problem 1.3 Implement a Queue class using two stacks (for hints, see problem 3.4/page 99 from "Cracking the coding interviews.."). What is the running time for enqueue() and dequeue()? Make your classes generic. Make sure to include running and space complexity for your methods.arrow_forwardScala programmingarrow_forward
- Language : c++ Question: Create a single link list of 8 nodes and exchange the addresses of even nodes with the odd nodes. An even nodes are the one which come at even place in the single link list like 2, 4, 6… And for the odd nodes which come at the odd place in the single link list like 1, 3, 5, 7…. An illustration is given belowarrow_forwardC++ Can someone answer the following code below in C++: Please add to the project a print statement that says how long each version ran in milliseconds please! Version 1 of the process creation hierarchy uses linked lists to keep track of child processes as described in section "The process control block", subsection "The PCB data structure". For the purposes of performance evaluation, the PCBs are simplified as follows: All PCBs are implemented as an array of size n. Each process is referred to by the PCB index, 0 through n-1. Each PCB is a structure consisting of only the two fields: parent: a PCB index corresponding to the process's creator children: a pointer to a linked list, where each list element contains the PCB index of one child process The necessary functions are simplified as follows: create(p) represents the create function executed by process PCB[p]. The function creates a new child process PCB[q] of process PCB[p] by performing the following tasks: allocate a…arrow_forwardProblem 4 and Problem 5arrow_forward
- 6.Need ri Write a JAVA program that will maintain a phone directory using a Linked-List. The program should be able to perform the following operations: Add persons details (first name, last name, phone number, city, address, sex and email) to the phone directory, where phone numbers in the directory have to be unique. (Note: each person record will store in one node in the linked-list and insert each person to the last) Delete any person details by a given phone number. Update telephone number by providing person first name. Display all details of persons from a phone directory. Search telephone number based on person first name. (Note: use sequential search to find all telephones for the given first name) Sort all persons in the phone directory ascending based on person first name. (Note: use bubble or selection sort to arrange the entire phone directory.arrow_forwardPEP/9 1. Translate the following linked list program into assembly language. Use the examples in fig 6.47 #include <iostream> using namespace std; struct node{ node* next; int data; }; // Simple insert routine for linked lists // in: call-by-reference to pointer // value to insert into the linked list // out: insert at the top of the linked list void insert(node*& ptr, int value) { node* temp = new node; temp->next = ptr; temp->data = value; ptr = temp; } int main() { node* root = NULL; node* p; int value; cin >> value; while (value >= 0) { insert(root, value); cin >> value; } for (p = root; p != NULL; p=p->next) cout << p->data << ' '; cout << endl; return 0; } Note: must use local variables, no globals, and must call the subroutine and use the parameters correctlyarrow_forwardNeed help in Stack/Queue Which of the following statements are correct about the time complexity of the operations of Queue implementations? If not, why? (ex. if 1 is incorrect, write fixed version, like dynamic array is used for implementation) If a circular array is used for implementation, the dequeue operation has a time complexity of O(n). If an array is used for the implementation with the first element in the queue always stored in index 0 of the array, the time complexity of the dequeue operation is O(n). If an array is used for the implementation with the first element in the queue always stored in index 0 of the array, the worst-case time complexity of the enqueue operation is O(n).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning