Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed 

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Chemical Principles

Authors: Steven S. Zumdahl, Donald J. DeCoste

7th edition

9781133109235, 1111580650, 978-1111580650

More Books

Students also viewed these Mechanical Engineering questions

Question

Find an equation of the given line. Slope is -2; x-intercept is -2

Answered: 1 week ago

Question

Equipment alignment and calibration

Answered: 1 week ago

Question

Test procedures

Answered: 1 week ago

Question

What are some common SITE challenges and issues?

Answered: 1 week ago