Question: typedef struct int key; . Observe the following multi-thread safe list insertion code: node_t { struct node_t *next; } node_t; mutex t m =
typedef struct int key; . Observe the following multi-thread safe list insertion code: node_t { struct node_t *next; } node_t; mutex t m = PTHREAD_MUTEX_INITIALIZER; node_t *head = NULL; int List Insert (int key) { } mutex lock (&m); node_t *n = malloc(sizeof (node_t)); if (n= NULL) { return -1; } //fail to insert n->key = key; n->next = head; head = n; mutex_unlock (&m); return 0; // insert // success The code has a big bug. Where is that big bug (only one)? Fix the code and make it work correctly.
Step by Step Solution
There are 3 Steps involved in it
The code you provided has a potential race condition that can lead to a bug The issue is with the wa... View full answer
Get step-by-step solutions from verified subject matter experts
