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

A file is to be shared among different processes, each of which has a unique num

ID: 674681 • Letter: A

Question

A file is to be shared among different processes, each of which has a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: The sum of all unique numbers associated with all the processes currently accessing the file must be less than n. Using pseudocode, write a monitor to coordinate access to the file.

Explanation / Answer

monitor fileSharer { enum {THINKING, WAITING, READING} state[N]; condition self[N]; int total; void open(int i) { state[i] = WAITING; if (i + total >= N) { self[i].wait(); } // Leaves monitor state[i] = READING; total += i; } void close(int i) { state[i] = THINKING; total -= i; // Can signal one waiting proc whose ID won't break bank. for (int x = N - total - 1; x >= 0; x--) { if (state[x] == WAITING) { self[x].signal(); break; } } } initialization.code() { for (int i = 0; i
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