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
Concept explainers
Expert Solution & Answer
Chapter 12.7, Problem 12.13PP
Program Description Answer
In the following program code, the main thread creates four peer threads and passes a pointer to each peer with unique id, Each peer copies the thread and displays the message present in that id.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
We said that only one method may be active in each given JVM thread. Why do you think so?
1. Consider the track line in railways. If multiple trains trying to access the same line it
should not allow because it will lead to collision. Now write a java program to schedule
the track for the train. Create 3 threads objects for the class Train for 3 trains and
schedule the Line by calling the getLine() (Synchronized method on the same Object but
only one thread will be able to execute it at a time) in the Line class.
Try pthreads.cpp. Modify it so that they run 3 threads (instead of two) and each thread runs a different function, displaying a different message. Copy-and-paste the source code and the outputs in your report.
/*
pthreads_demo.cpp
A very simple example demonstrating the usage of pthreads.
Compile: g++ -o pthreads_demo pthreads_demo.cpp -lpthread
Execute: ./pthreads_demo
*/
#include <pthread.h>
#include <stdio.h>
using namespace std;
//The thread
void * thread_func (void *data)
{
char *tname = (char *) data;
printf("My thread identifier is %s\n", tname);
pthread_exit (0);
}
int main ()
{
pthread_t id1, id2; //thread identifiers
pthread_attr_t attr1, attr2; //set of thread attributes
char *tnames[2] = { "Thread 1", "Thread 2" }; //names of threads
//get the default attributes
pthread_attr_init (&attr1);
pthread_attr_init (&attr2);
//create the threads
pthread_create (&id1, &attr1, thread_func, tnames[0]);…
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
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
- Implement a solution to the critical section problem with threads using semaphores. you must add a third counting thread which counts by 1 each time it enters its critical section to 3,000,000. Each counts to 3,000,000 for a total of 9,000,000.arrow_forwardWrite a Java program to implement two threads such that one thread prints all the numbers that are divisible by 3 or 5 but not both from 1 to 100 and other thread prints all the numbers that are divisible by both 3 and 5 from 1 to 100. (use Thread class ). Note : Each thread has a delay of 200 millisecond after printing one numberarrow_forwardWrite a program that has a counter as a global variable. Spawn 10 threads in theprogram, and let each thread increment the counter 1000 times in a loop. Print the finalvalue of the counter after all the threads finish—the expected value of the counter is10000. Run this program first without using locking across threads and observe theincorrect updating of the counter due to race conditions (the final value will be slightly lessthan 10000). Next, use locks when accessing the shared counter and verify that the counteris now updated correctlyarrow_forward
- I'm trying to construct 2 methods to sort an array One method will sort an array in ascending order the other method will sort the array in the sending order. To try to implement concurrency of threading. Writen in java.arrow_forwardWrite a C program called threadcircuit to run on ocelot which will provide a multithreaded solution to the circuit-satisfiability problem which will compute for what combinations of input values will the circuit output the value 1. This is the sequential solution, which is also attached. You should create 8 threads and divide the 65,536 test cases among them. For example, if p=8, each thread would be responsible for roughly 65,536/8 number of iterations (if it's not divisible, some threads can end up with one more iteration than the others). #include <stdio.h>#include <sys/time.h> /* Return 1 if 'i'th bit of 'n' is 1; 0 otherwise */#define EXTRACT_BIT(n,i) ((n&(1<<i))?1:0) int check_circuit (int z) {int v[16]; /* Each element is a bit of z */int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i);if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3])&& (!v[3] || !v[4]) && (v[4] || !v[5])&& (v[5] || !v[6]) &&…arrow_forwardWrite a C program called threadcircuit to run on ocelot which will provide a multithreaded solution to the circuit-satisfiability problem which will compute for what combinations of input values will the circuit output the value 1. This is the sequential solution, which is also attached. You should create 4 threads and divide the 65,536 test cases among them. For example, if p=4, each thread would be responsible for roughly 65,536/4 number of iterations (if it's not divisible, some threads can end up with one more iteration than the others). #include <stdio.h>#include <sys/time.h>/* Return 1 if 'i'th bit of 'n' is 1; 0 otherwise */#define EXTRACT_BIT(n,i) ((n&(1<<i))?1:0)int check_circuit (int z) { int v[16]; /* Each element is a bit of z */ int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i); if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3]) && (!v[3] || !v[4]) && (v[4] || !v[5]) && (v[5]…arrow_forward
- Above is a python script that scans wifi networks. Please explain each line of code. Write an explanatory note about the libraries used and their methods.arrow_forwardI have a web server program. It works as follows: the parent thread waits for new client connections. Once a new client connection comes in, the parent thread creates a child thread that services the client connection while the parent thread goes back and waits for more connections. Once the client connection finishes, the corresponding servicing child thread exits. When my code has undergone the usual code review process in my company, it has received major criticisms for being gravely inefficient. Name the optimization technique that I I have neglected to use? Clearly explain the technique and how the technique works and how it would improve the performance of my code.arrow_forwardWe previously said that each JVM thread can only have one method active. Why do you think this?arrow_forward
- Create two Thread subclasses, one with a run() that starts up, captures the reference of the second Thread object and then calls wait(). The other class run() should call notifyAll() for the first thread after some number ofn seconds have passed, so the first thread can print a messagearrow_forwardin java fx Write a program that launches 1,000 threads. Each thread adds 1 to a variable sum that initially is 0. You need to pass sum by reference to each thread. In order to pass it by reference, define an Integer wrapper object to hold sum. Run the program with and without synchronization to see its effect.arrow_forwardSolve asap . I will upvote sure.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education