Notes/UNB/Year 4/Semester 1/CS3418/10-27-2023.md
2024-01-22 10:12:48 -04:00

1.2 KiB

Lecture Topic: Producer Consumer & Reader Writer Problem

Lecture 20

If you were to use two semaphores and a mutex you can have multiple producers and multiple consumers.

Producer

while(true) {
	// produce am item
	wait(empty)
	wait(mutex)
	buffer[index] = item
	index++
	signal(mutex)
	signal(full)
}

Consumer

while(true) {
	// consume an item
	wait(empty)
	wait(mutex)
	item = buffer[index]
	index--
	signal(mutex)
	signal(full)
}

Slides Chapter 7

In the reader writer problem, you can encounter the "First reader-writer problem", in which the writer process never writes. A "second reader-writer problem" in which when a writer is ready to write, no reader is available. These problems can sometimes be solved by kernel reader writer locks.

Dining Philosopher problem

Slides Chapter 8

Deadlock Characterization:

Deadlocks can occur if four conditions are true simultaneously

  • Mutual exclusion: only one process can use a resource