Question
Observe the following multi-thread safe list insertion code: typedef struct _node_t { int key; struct __node_t *next; } node_t; mutex_t m = PTHREAD_MUTEX_INITIALIZER; node
Observe the following multi-thread safe list insertion code: typedef struct _node_t { int key; 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Chemical Principles
Authors: Steven S. Zumdahl, Donald J. DeCoste
7th edition
9781133109235, 1111580650, 978-1111580650
Students also viewed these Mechanical Engineering questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App