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
Expert Solution & Answer
Book Icon
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”,...

Blurred answer
Students 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…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning