Concepts Flashcards

Some concept that is relevant to concurrent programming.

1
Q

What are the four necessary conditions for deadlock?

A

Mutual exclusion, hold and wait, no resource preemption and circular wait.

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

What is mutual exclusion?

A

Mutual exclusion is a concept where only one thread can access a resource at a time.

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

What is hold and wait?

A

It is a situation where a thread can reserve a resource and then wait for another to be available.

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

What is “no resource preemption”?

A

It is the concept where a thread cannot be forced to release an held resource.

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

What is circular wait?

A

It is the concept where resources can be accessed by threads so that it creates a circular dependency.

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

What is a deadlock?

A

A deadlock is a situation that occurs when multiple threads are waiting for each other do release a resource.

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

What is a livelock?

A

A livelock is a situation where we have circular resource dependencies between threads and end up not being able to proceed. A key characteristic that differentiates a livelock from a deadlock is that the threads are constantly changing resource with one another.

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

What is starvation?

A

Starvation is a situation that occurs when a thread needs a resource to proceed but it is more frequently requested by other threads. Thus the thread that requests the resource less frequently will have to wait a long time to access the resource.

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

What is race condition?

A

A race condition occurs when multiple threads try to access and modify shared data at the same time. Due to context switches (change to another thread) the data is dependent on the thread scheduling and thus which thread access the data at what time.

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

What are four ways you can ensure mutual exclusion?

A

Stack confinement, instance confinement, thread confinement and immutability.

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

What is stack confinement?

A

Stack confinement is a way of ensuring thread-safety by ensuring the object only can be reached through a local variable. Since local variables are intrinsically confined to single thread the object is too. This will keep the object thread-safe.

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

What is instance confinement?

A

Instance confinement is a way of ensuring thread-safety by properly using locks to ensure only one threads modifies or accesses the resource at a time. An example of this is a monitor i Java.

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

What is thread confinement?

A

Thread confinement is a way of ensuring thread safety by limiting a resource to a single thread. An example of this is the Swing EDT (Event Dispatch Thread).

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

What is immutability?

A

Immutability is a way of ensuring thread-safety by making it unchanging. Since it cannot be modified it is inherently thread-safe.

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

What is a monitor in Java?

A

A monitor is a class that uses the keyword synchronized. Methods that are synchronized can only be accessed by one thread at a time.

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

What is a volatile variable?

A

Volatile variables are variables that should always be read from the memory and not cache. Thus the value is immediately visible to the other threads. Although race-condition is still possible.

17
Q

What is a critical section?

A

A critical section is parts of code that are accessed by multiple threads simultaneously.