Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 5.15 Operating Systems: Consider how to implement a mutex lock using an atomic hardware instruction. Assume that the following structure de?ning the mutex lockisavailable:

Chapter 5.15 Operating Systems: Consider how to implement a mutex lock using an atomic hardware instruction. Assume that the following structure de?ning the mutex lockisavailable: typedef struct{ int available; }lock;

(available == 0) indicates that the lock is available, and a value of 1 indicates that the lock is unavailable. Using this struct, illustrate how the following functions can be implemented using the test and set() and compare and swap() instructions: void acquire(lock *mutex) void release(lock *mutex) Be sure to include any initialization that may be necessary. Exercises 245 do {while (true) { flag[i] = want in; j = turn; while (j != i) { if (flag[j] != idle) { j = turn; else j = (j + 1) % n; } flag[i] = in cs; j = 0; while ( (j < n) && (j == i || flag[j] != in cs)) j++; if ( (j >= n) && (turn == i || flag[turn] == idle)) break; } /* critical section */ j = (turn + 1) % n; while (flag[j] == idle) j = (j + 1) % n; turn = j; flag[i] = idle; /* remainder section */ } while (true);

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions