Week 10 & 11
Week 10 & 11
Department of Computer
Science
HITEC University Taxila
Operating Systems
Week 10 & 11
● Cooperating Processes:
● A process that can affect or be affected by other
processes executing in the system
● Can be allowed to share data
● Concurrent access to shared data may result in data
inconsistency
● Process synchronization is needed for data
consistency
● the way by which processes that share same
memory space are managed in an OS.
while (true) {
/* produce an item in next produced */
while (true) {
while (counter == 0)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
counter--;
/* consume the item in next consumed */
}
Memory
● acquire() {
while (!available); /* busy wait */
available = false;
}
● release() {
available = true;
}
● do {
acquire()
critical section
release()
remainder section
} while (true);
● Busy waiting:
● When one process is in the critical section, any
other process that tries to access the critical
section must loop continuously in the entry
section code.
● Wastes the CPU cycles that some other
processes might be able to use productively.
● This type of semaphore is also called spinlock
because the process spins while waiting for the
lock.