Lecture 13: Synchronization 5: Dining+Monitors Flashcards

1
Q

Semaphores Variations

A
  1. Binary semaphore

2. Counting semaphore:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Binary semaphore

A

(resource count of 0/1, available/unavailable)
-one thread can hold lock at a time (n = 1)
good for critical sections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Counting semaphore

A

(resource count of n)

n threads can hold lock at a time (good for other synchronization problems)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Dining Philosopher

Solution 1

A

Goal: Ensure only one philosopher grabs a given chopstick at a time

Solution 1: Array of binary semaphores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Dining Philosophers

Solution 2

A

Idea: Ensure only one philosopher grabs both of his chopstick at a time

Solution 2: Make grabbing chopsticks a critical section (i.e., add binary semaphore, mutex)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Dining Philosophers

Solution 3

A

Idea: Rather than synchronizing on chopsticks & their availability, synchronize on

-philosophers & their “state” (HUNGRY, THINKING, EATING) Philosophers declare themselves to be hungry, & wait for
neighbors to finish eating

Solution 3:

  • Array of philosopher “states” (state [0 … n-1])
  • Array of philosopher (binary) semaphores (phil [0 … n-1])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Software Abstraction 1: Semaphores

A

-Useful Abstraction of HW Primitives (Lock + Wait Queue)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Software Abstraction 1: Semaphores Pro

A

simple to implement conceptually simple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Software Abstraction 1: Semaphores Con

A

-still low-level

  • some synchronization solutions very tricky with semaphores: (e.g., R/W (writers-favored))
    sometimes used in unintuitive ways
    • e.g, bounded buffers – FULL, EMPTY semaphores not used as locks (initialized to 0)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Software Abstraction 2: Monitors

A
  • A high-level synchronization abstraction

- Objects with built-in, thread-at-a-time access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

wait()

A
  • blocks thread + releases lock
  • it checks the interruption status of thread − throws exception if true.

When thread t calls …

a. t releases object lock
b. t’s state = BLOCKED
c. t placed in wait set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

notify()

A

-wakes thread blocked on object

When thread t calls …

a. selects some thread t’ from wait list
b. moves t’ to entry set
c. state of t’:= RUNNABLE (Can again compete for lock)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly