ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > student directories >
homework4 Version 0
👤 Author: by 15988816214163com 2019-12-24 01:51:56
think about your possible case about process synchronization, and give out a solution for the problem.

The library has 100 seats, and each reader who enters the library must register on the registration form, and when they withdraw, they must cancel the registration form. How many programs? How many processes are there? (Answer: one program; one process for each reader)


(1) When there are no seats in the library, late readers wait in the library (blocking)

(2) When there are no seats in the library, the readers who come later do not wait, and go home immediately.


Solution (1)

Set the semaphore: S = 100; MUTEX = 1

P (S)

P (MUTEX)

Register

V (MUTEX)

read

P (MUTEX)

Log out

V (MUTEX)

V (S)



Solution (2)

Set integer variable COUNT = 100;

Semaphore: MUTEX = 1;

P (MUTEX);

IF (COUNT == 0)

{V (MUTEX);

RETURN;

}

COUNT = COUNT-1;

Register

V (MUTEX);

read

P (MUTEX);

COUNT = COUNT + 1;

V (MUTEX);

RETURN;

Please login to reply. Login

Reversion History

Loading...
No reversions found.