A. In Figure 12.43, we eliminated the race by allocating a separate block for each integer ID.
Question:
A. In Figure 12.43, we eliminated the race by allocating a separate block for each integer ID. Outline a different approach that does not call the malloc or free functions.
B. What are the advantages and disadvantages of this approach?
Figure 12.43
Transcribed Image Text:
1 #include "csapp.h" 2 #define N 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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", return NULL; myid);
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (2 reviews)
A Another approach is to pass the integer i directly ...View the full answer
Answered By
Susan Juma
I'm available and reachable 24/7. I have high experience in helping students with their assignments, proposals, and dissertations. Most importantly, I'm a professional accountant and I can handle all kinds of accounting and finance problems.
4.40+
15+ Reviews
45+ 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
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Division of Motor Vehicles (DMV) is part of the State Department of Transportation (DOT). The purpose of that department is to ensure the safety and free flow of people and goods throughout the...
-
What HRM functions could an organization provide through self-service? What are some advantages and disadvantages of using self-service for these functions?
-
Explain how you solve problems during the implementation of your projects. Does this operate as a formal approach and/or use specific supportive techniques?
-
Your Aunt Sally has a large portfolio of corporate bonds of different maturities. She has asked your advice on whether to buy more or get rid of some. You anticipate an increase in interest rates in...
-
Explain the difference in treatment for short-term leasing (lease terms of 12 months or less) versus longer-term operating leases. Is there any difference in the accounting treatment of long-term...
-
Determine the sidelighting workplace illuminances for a \(20 \mathrm{ft}\) long, \(15 \mathrm{ft}\) wide (deep), \(8 \mathrm{ft}\) high light-colored room with a \(15 \mathrm{ft}\) long by \(5...
-
Tom Brennan opened Brennan's Cleaning Service on July 1, 2014. During July the following transactions were completed. July 1 Stockholders invested $20,000 cash in the business in exchange for common...
-
Windy introduces a new compact music player that carries a two-year warranty against manufacturer's defects. Based on industry experience with similar product introductions, warranty costs are...
-
The rand_r function in Figure 12.40 is implicitly reentrant. Explain. Figure 12.40 1 2 3 4 5 6 /* rand_r - return a pseudorandom integer on 0..32767 */ int rand_r(unsigned int *nextp) { } *nextp...
-
Consider the following program, which attempts to use a pair of semaphores for mutual exclusion. A. Draw the progress graph for this program. B. Does it always deadlock? C. If so, what simple change...
-
To what date does a serial format of 4526 correspond?
-
On January 1, 2023, Amanda company acquires a new building for $870,000,000 cash. The building will be used as a showroom. The company also spent $120,000 in legal fees to transfer the property of...
-
Sales commissions Advertising expense Miscellaneous administrative expenses Office salaries expense Customer support expenses Research and development expense 15% of sales 20% of sales $7,000 per...
-
Edgar and search for the Amazon annual report ( 1 0 - K ) for the year ended December 3 1 , 2 0 1 9 , using EDGAR ( Electronic Data Gathering, Analysis, and Retrieval system ) . Visit www . sec . gov...
-
What is the annual employee maximum for the Qu bec Employment Insurance premium?
-
Tin Co purchases $250 worth of metal from Steel Co. Tin Co agrees to pay Steel Co in 60 days time. What is the double entry to record the purchase in Steel Co's books?
-
You have an equimolar mixture of the gases SO 2 and O 2 , along with some He, in a container fitted with a piston. The density of this mixture at STP is 1.924 g/ L. Assume ideal behavior and constant...
-
Test your confidence in the following Project Decisions: SI. # Question 01 02 03 04 05 06 07 08 09 10 How many years did it take to construct the largest Egyptian Pyramid- Pyramid of Cheops? When was...
-
Another pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect of the computer. Consider a computer running a program that requires...
-
Aside from the smart cell phones used by a billion people, list and describe four other types of computers.
-
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume...
-
For Louisiana and Caddo Parish (where Shreveport is located) there is a $75,000 homestead exemption. Thus $75,000 is deducted from the assessed value and then the rate is multiplied by the value...
-
Imagine you are an IT consultant. A small city wants to install a new city-wide MAN designed to integrate all local government departments, including those which might have public-facing functions...
-
If you were anywhere near the East Coast in the 1980s, you undoubtedly saw those TV commercials. The raucous ads saturated the airwaves in the tri-state area and helped Crazy Eddie's quickly become...
Study smarter with the SolutionInn App