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.
Course Title : Operating SystemQuestion : Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. This scheme permits the physical address space of a process to be non – contiguous.   Given below is one of the page replacement algorithm program, you are to first identify which algorithm (FIFO, Optimal Page Replacement, Least frequently used) is implemented in given c-code. Please consider following reference string for this page replacement algorithm(1,2,3 5,1,3,4,5,6,1,5,3,2) with 4 page/frame size. There are some errors in this program, you have to correct it first, and then explain compiled output with each miss or hit condition. Note: Show complete procedure with detail steps/screenshots with your arid number(18-arid-2929) #include <stdio.h> void main()   { intpos,c,m,maxi,i,k,nf,count,j=0,pf=0,np=0; printf("enter no. of pages"); scanf("%d",&np); int s[np]; printf("Enter pages sequence…
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…
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