Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

typedef struct int key; struct } node_t; Observe the following multi-thread safe list insertion code: _node_t { node t *next; mutex t m =

image text in transcribed 

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

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

Financial Accounting

Authors: David Spiceland

6th Edition

1260786528, 9781260786521

More Books

Students also viewed these Accounting questions