Question: typedef struct int key; struct } node_t; Observe the following multi-thread safe list insertion code: _node_t { node t *next; mutex t m =
typedef struct int key; struct } node_t; Observe the following multi-thread safe list insertion code: _node_t { node t *next; mutex t m = PTHREAD MUTEX INITIALIZER; node_t *head = NULL; int List Insert (int key) { mutex lock (&m); node t *n = if (n= NULL) { return -1; } //fail to insert malloc(sizeof (node_t)); n->key = key; n->next = head; head = n; // insert mutex_unlock (&m); // success } return 0; 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
Get step-by-step solutions from verified subject matter experts
