3. A file is to be shared among different processes, each of which owns a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: the sum of the unique numbers owned by the processes currently accessing the file must be less than a defined constant MAX_N. Complete access_file(), finish_access(),
Problem 3. A file is to be shared among different processes, each of which owns a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: the sum of the unique numbers owned by the processes currently accessing the file must be less than a defined constant MAX_N. Complete access_file(), finish_access(), and initialization() as below to coordinate file access. (Hint: see an example in Slide 3.39, however, a loop, instead of an ifstatement, is needed in access_file() b/c an resumed process is not guaranteed to have a unique number that works.)
monitor file_access {
int curr_sum; //sum of numbers owned by the processes currently accessing the file
condition c; //allowing two operations wait() and signal() defined in Slide 3.33
void access_file(int my_num) {...} //called by a process to request file access
void finish_access(int my_num) {...} //called by a process when completing file access
void initialization() {...} //initializing variable(s)
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images