Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is for Operating Systems Concepts... There are N threads that want to get i

ID: 3718585 • Letter: T

Question

This is for Operating Systems Concepts...

There are N threads that want to get into the critical section for modifying a shared variable. Do you think that by using the program provided below all of them eventually will be able to get into the critical section? (Evaluate the fairness) 1 int FotchAndAdd (int .ptr) int old # *ptr; ptr- old+1; roturn old typado f struct lock t int ticket int turn lock t void lock init Clock tlock) Lock->ticket-0 lock->turn-0 10 void lock (lock t-lock) int myturn FetchAndAdd (&lock-ticket;) while lock-sturnmyturn 12 13 14 15 16 17 void unlock (lockt lock) 18 19 17 spin lock->turn-lock-sturn1

Explanation / Answer

the solution you have approached is similar to mutex lock, it works efficiently. but for a better approach i would recommend you to use semophore, where there is more apportunity for all threads to get into crictical section.

The proposed solution looks fair enough

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote