Understanding Threads and Locks Flashcards

Explore essential concepts of threads, locks, and concurrency with these engaging flashcards. (9 cards)

1
Q

What is deadlock?

A

Deadlock is when two or more threads become blocked, because they are each waiting for something the other thread has. This reliance is a mutual dependancy between the two.

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

What is lock overhead?

A

Locking is storage expensive, as it is another variable that needs to be maintained. This required storage is called lock overhead.

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

How can you mitigate lock overhead?

A

If there’s a cost associated to a lock, reduce overhead by having fewer locks. You can decrease the number of locks by locking larger amounts of code

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

What is lock contention?

A

Lock contention is the time spent waiting for another thread to give up a lock, so work can be continued

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

How can you mitigate lock contention?

A

You can reduce lock contention by placing locks on smaller amounts of code. This means less code has to be completed before a lock is given up.

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

What is a thread pool?

A

You can create multiple threads to begin with, and assign them tasks, rather than creating threads as you go along

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

What is an advantage of thread pools?

A

There is no overhead for creating new threads, you just use ones from the pool

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

What are 2 disadvantages of thread pools?

A

1) Deadlock may happen if you run out of threads (a locked action will not unlock until right amount of threads available for task completion) 2) Thread leakage, if a thread has an exception not dealt with, the thread cannot be used

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

What is the difference between threads and co-routines?

A

1) Threading offers concurrency and parallelism. Coroutines offer concurrency but not necessarily parallelism. 2) Coroutines yield control at fixed points, Threading does not, leaves that to the processor.

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