COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
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
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…
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…
Chapter 12 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
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
- Problem 1 (Stacks): Let S1 and S2 be two stacks. 1. It is possible to keep two stacks in a singlearray, if one grows from position 1 of the array, and the other grows from the last position? 2.Write a procedure Push(x, S) that pushes element x onto stack S, where S is one or the other ofthese two stacks. Include all necessary error checks in your procedure.arrow_forwardProblem 1 (Stacks): Let S1 and S2 be two stacks. 1. It is possible to keep two stacks in a singlearray, if one grows from position 1 of the array, and the other grows from the last position? 2.Write a procedure Push(x, S) that pushes element x onto stack S, where S is one or the other ofthese two stacks. Include all necessary error checks in your procedure. Problem 2 (Stacks): Consider the fundamental theorem of arithmetic, which is stated as follows:Every positive integer greater than 1 can be written uniquely as a prime or as the product of twoor more primes, where the prime factors are written in order of nondecreasing size. We want touse a stack to read a number and print all of its prime divisors in descending order. For example,with the integer 2100, the output should be:7 5 5 3 2 21. Write an algorithm, called Prime_Factorization, which accepts a positive integer greaterthan 1, and generates its prime factorization according to the above-mentioned theorem.[Hint: The smallest…arrow_forwardLanguage : 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_forward
- 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_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_forwardComplete 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_forward
- # i need solution faster please in c++ or java # assume the processor has many processes that are needed to be processed in the same time , each process needs a time to finished , so the processor puts them in the ordered queue such that the process with minimum time comes first in front of the queue .i.e the processor should serve the fewest time firstly.1. write a function to insert a process , in its proper place.(sort queue). 2. write a function to find the total working time of the processor.Hint : dont use any extra data structure only use queue.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_forward5. The creeping problem occurs when a queue is implemented as an array. (a) Define the creeping problem. (b) Describe how to implement a queue as an array in order to avoid the creeping problem. (c) Write the C++ method Join for the new type of Queue described in (b) above.arrow_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_forwardUse C++ to Solve This. 4: Write a program for Queue operation. The program must display the address of element being Pushed or Popped after every Push and Pop operation.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_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