In Figure 12.43, we might be tempted to free the allocated memory block immediately after line 14
Question:
In Figure 12.43, we might be tempted to free the allocated memory block immediately after line 14 in the main thread, instead of freeing it in the peer thread. But this would be a bad idea. Why?
Figure 12.43
Transcribed Image Text:
1 #include "csapp.h" 2 #define N 4 3 4 5 67 8 9 10 11 12 13 14 1567 18 19 20 21 22 23 24 25 26 27 28 void *thread (void *vargp); int main() { } pthread_t tid [N]; int i, *ptr; } for (i = 0; i < N; i++) { ptr Malloc(sizeof (int)); *ptr 1; Pthread_create(&tid[i], NULL, thread, ptr); = = } for (i = 0; i < N; i++) Pthread_join(tid[i], NULL); exit(0); /* Thread routine */ void *thread (void *vargp) { int myid*((int *)vargp); Free (vargp); printf("Hello from thread %d\n", myid); return NULL;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 0% (1 review)
If we free the block immediately after the ca...View the full answer
Answered By
Diane Joyce Pastorin
Please accept my enthusiastic application to solutioninn. I would love the opportunity to be a hardworking, passionate member of your tutoring program. As soon as I read the description of the program, I knew I was a well-qualified candidate for the position.
I have extensive tutoring experience in a variety of fields. I have tutored in English as well as Calculus. I have helped students learn to analyze literature, write essays, understand historical events, and graph parabolas. Your program requires that tutors be able to assist students in multiple subjects, and my experience would allow me to do just that.
You also state in your job posting that you require tutors that can work with students of all ages. As a summer camp counselor, I have experience working with preschool and kindergarten-age students. I have also tutored middle school students in reading, as well as college and high school students. Through these tutoring and counseling positions, I have learned how to best teach each age group.
4.60+
2+ Reviews
10+ Question Solved
Related Book For
Computer Systems A Programmers Perspective
ISBN: 9781292101767
3rd Global Edition
Authors: Randal E. Bryant, David R. O'Hallaron
Question Posted:
Students also viewed these Computer science questions
-
Hyten Corporation On June 5, 1998, a meeting was held at Hyten Corporation, between Bill Knapp, Director of Marketing/Sales, and John Rich, director of engineering. The purpose of the meeting was to...
-
Never mind computers and tech services. IBM's radical new focus is on revamping customers' operations -- and even running them It was over a lunch in Cincinnati two years ago that IBM Chief Executive...
-
Assignment 5: Hash Table implementation andconcordance There are three parts to this assignment. In the first two parts,you will complete the implementation of a hash map and aconcordance program. In...
-
When Ralph Lauren makes shirts to a customers exact preferences, what utility is provided?
-
Broxholme Industries has sales of $40 million, equity totaling $27.5 million, and an ROS of 12%. The sustainable growth rate has been calculated at 10.9%. What dividend payout ratio was assumed in...
-
You are the vice president of Worldwide InfoXchange, headquartered in Minneapolis, Minnesota. All shareholders of the firm live in the United States. Earlier this month, you obtained a loan of 10...
-
It has been estimated that a 400 MW expansion of the existing SEGS solar plant in California would cost \(\$ 2.4\) billion. Estimate the expected capital costs of the generation facility in dollars/...
-
Presented below are selected transactions at Ridge Company for 2015. Jan. 1 Retired a piece of machinery that was purchased on January 1, 2005. The machine cost $62,000 on that date. It had a useful...
-
using the following maturity terms and annual interest rate : Maturity Annual Interest Rate (%) 1 Year 1.25% 2 Years 1.5% 5 Years 2% 10 Years 3% Assuming joe and julia has their first yearly saving...
-
In Linux systems, typing Ctrl+D indicates EOF on standard input. What happens if you type Ctrl+D to the program in Figure 12.6 while it is echoing each line of the client? Figure 12.6 1 #include...
-
Assume that a CGI program needs to send dynamic content to the client. This is typically done by making the CGI program send its content to the standard output. Explain how this content is sent to...
-
Assume p is T, q is T, and r is F. Find the truth value for each of the compound statements in Problems 3540. a. (pVq) Ar
-
If YOU were to devise a personal strategy for how to behave in challenging interpersonal situations, outline the steps to this strategy. In addition, indicate to what degree would this strategy use...
-
What are Task Force teams? What are the unique features of the task force teams and how do these affect the team dynamics. Explain with two examples.
-
Virtual meetings using collaboration software is generally used when participants are dispersed over a large geographic area. Research on the Internet for software being used today and register for a...
-
Utilize your understanding of intelligence and achievement testing to assign an axis one or two diagnosis to Bob Schmoe from the Sample Intelligence-Achievement Report in the Module Resources folder....
-
As a network security analyst We often need to do research at work to find answers to issues or challenges we experience, whether big or small. Sometimes we also need to research potential new...
-
Represent the following plots. a. PV/ n (y axis) versus P (x axis) for a real gas that obeys the equation PV/ n = a + P b. Change in momentum per impact versus mass of an individual gas particle for...
-
Why is inventory management important for merchandising and manufacturing firms and what are the main tradeoffs for firms in managing their inventory?
-
Calculate by hand 8.625 10 1 divided by -4.875 10 0 . Show all the steps necessary to achieve your answer. Assume there is a guard, a round bit, and a sticky bit, and use them if necessary. Write...
-
Calculate (3.984375 10 - 1 + 3.4375 10 -1 ) + 1.771 10 3 by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in the...
-
Calculate 3.984375 10 -1 + (3.4375 10 -1 + 1.771 10 3 ) by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in the...
-
Required information (Algo) Change in estimate; useful life and residual value of equipment Wardell Company purchased a minicomputer on January 1, 2022, at a cost of $54,000. The computer was...
-
You are given the following information: Boston Equity Mutual Fund Total assets $ 910 million Total liabilities $ 6 million Total number of shares 42 million Calculate the net asset value for the...
-
if GCI accepts the replaced good but one week later discovers that the new press component is incompatible with the first two components, may GCI still reject the goods despite the fact that it has...
Study smarter with the SolutionInn App