Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

    • image text in transcribed  

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

Step: 1

The code you provided has a potential race condition that can lead to a bug The issue is with the wa... 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_2

Step: 3

blur-text-image_3

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

Governmental and Nonprofit Accounting

Authors: Robert Freeman, Craig Shoulders, Gregory Allison, Robert Smi

10th edition

132751267, 978-0132751261

More Books

Students also viewed these Finance questions

Question

Distinguish between a priori and a posteriori knowledge.

Answered: 1 week ago