Lecture 11: Synchronization 2 Flashcards

1
Q

Algorithm 1: Strict Alternation

A
Each thread takes turns getting access to its CS
1.
Mutual Exclusion?
•
Thread only has access to critical section when turn has appropriate value
•
With n threads, thread i waits for at most n 1 threads to
enter/exit their critical sections
2.
Bounded Wait?
3.
Progress? No
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Mutex

A

Synchronization mechanism for enforcing limits on access to the CS

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

Algorithm 2: “After You”

A

Thread specifies interest in entering critical section. Can enter if other thread is not interested
“Mutual Exclusion: Yes
• Thread only has access to critical section when other threads’ flag == 0
Progress: No
• Both threads could express interest with neither allowed
entry into critical section
Bounded Wait: No
• Possible for threads to starve forever”

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

Algorithm 3: Peterson’s Algorithm

A

Combines algorithms 1 and 2. Threads take turns, but a thread skips its turn if it’s not interested and another thread is

“• thread A gets access to C/S if (flag1” “== FALSE) or (turn” “== 0)”
“• thread B gets access to C/S if (flag0” “== FALSE) or (turn” “== 1)”

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

Disabling Interrupts

A

“Thread code works as follows …”
“while (TRUE) {
disable interrupts

   enable interrupts

}”
+: Easy to see that it works

–:Overkill
1. Disables all interrupts (e.g.: I/O)
2. Disallows concurrency with threads in non
critical sections
–: Doesn’t work for multicore systems
(Each CPU has own interrupts: threads on different
CPU’s can access their critical sections at same time)

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

Test and Set ( TS)

A
"New AL instruction (  Atomic)
TS (i) =
1.  temporarily saves value of Mem[i]
2.  sets Mem[i] := TRUE
3.  returns original value of Mem[i]"

can be used to implement “:Locking”

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