Operating System Notes
Readers and Writers Problem:
Policy decisions:
Readers reading the resource. If a writer comes followed by a reader, whether we let the reader in first or the writer in first. If we let the readers in first, we probably have a situation of writers’ starvation. We do not preempt the resource.
Set the amount of readers that can get in front of the writers.
//————————————————-
typedef int semaphore;
semaphore protectCount = 1; //mutex
semaphore protectDB = 1; //mutex
int rc = 0;
void beforeWriting() {
P(protectDB);
}
void afterWriting() {
V(protectDB);
}
void beforeReading() {
P(portectCount);
if(++rc == 1) {
P(protectDB);
}
V(protectCount);
}
void afterReading() {
P(portectCount);
if(–rc == 0) {
V(protectDB);
}
V(protectCount);
}
//————————————————-
Lock the shared resources.
Do not access the value of semaphores.
Memory Management:
Binding:
- If a program has a line: int x; When is the address of x decided.
- At compile time
- At load time
- At run time