Mod 2: Critical Section / Mutual Exclusion Flashcards

1
Q

What are some mechanisms to control access to shared resources?

A

(1) Locks
(2) Mutexes
(3) Semaphores
(4) Monitors
(5) Condition variables

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

What are some patterns for coordinating accesses to shared resources?

A

(1) Write-Reader
(2) Producer-Consumer (bounded buffer)

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

What is mutual exclusion?

A

Allowing only one thread to be in its critical section at a certain time, it means “not simultaneous”

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

How is mutual exclusion usually programmed?

A

By using locks

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

What is “condition synchronization”?

A

Signaling a condition (via shared variable) to allow threads waiting for an event signaled from another thread

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

What causes busy wait?

A

When something is waiting for a condition to come through and repeatedly test a variable until it comes true

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

When is synchronization needed?

A

Whenever a shared resource (a variable) is to be accessed by multiple threads

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

What is “critical sections/regions”?

A

Code blocks that may get incorrect results if executed simultaneously, these often access shared variables and must be protected

i.e statement that must not be executed by more than one thread at the time or part of code manipulating shared modifiable resources

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

What is mutual exclusion?

A

Mechanism that allows only one thread to enter the CS (critical section) at a time

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

What should we do to avoid race condition?

A

(1) Determine which part of the code is critical
(2) Ensure mutual exclusion

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

What is four requirements for CS solution?

A

(1) ME
(2) Progress (no deadlock or starvation)
(3) Fairness (no starvation)
(4) No assumption on performance

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

What does the requirement “progress” mean in CS context?

A

When no thread is in a CS, any thread requesting to enter must be allowed to do so without delay

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

What does “Fairness” mean in CS context?

A

That any thread waiting to access CS will at some point do that

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

What does “no assumption on performance” mean in CS context?

A

Overhead of entering and exiting should be small

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

What does “bounded wait” mean?

A

That there’s an uppe bound to the number of times a thread is allowed to enter its CS while other threads are waiting

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

How is a lock used?

A

(1) Aquire lock before entering CS
(2) Execute CS
(3) Release lock

Aquiring a lock must a atomic

17
Q

How do we aquire a lock in Java?

A

By using the keyword SYNCHRONIZED

18
Q

Explain the CS properties

A

(1) ME: only one thread at a time can execute CS
(2) Progress: a thread outside CS cannot prevent another from entering CS
(3) Bounded waitin: a thread waiting to ENTER CS will eventually do so
(4) Performance: overhead of entering and exiting should be small
(5) Fairness: some thread should not wait longer than others

19
Q

What does “overhead” mean?

A

overhead is any combination of excess or indirect computation time, memory, bandwidth, or other resources that are required to perform a specific task

20
Q

What is the “read-write-problem”?

A

When one or more threads look up data while other threads change values in the same data, eg. database record may be read while other threads update the records

21
Q

What are the fundamentals rules for the “read/write problems solution”?

A

(1) Only mulitple readers can have concurrent access
(2) Writes cannot have concurrent access
(2) a reader and a write cannot have concurrent access

22
Q

What method can be used for condition synchronization in Java?

A

wait( )
notify( )
notifyAll( )