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
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

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 ", return NULL; myid);
Step by Step Solution
3.37 Rating (153 Votes )
There are 3 Steps involved in it
A Another approach is to pass the integer i directly ... View full answer
Get step-by-step solutions from verified subject matter experts
