Concurrency Flashcards

1
Q

Do threads use the same address space, or do they copy the same address space? Why?

A

They use the same address space, so that they do not need to perform a context switch each time we switch threads.

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

What happens to the stack when we run a multithreaded process?

A

Each thread will have its own stack.

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

What are some reasons for using threads?

A

Parallelism
To avoid blocking programs due to slow IO
It is easy to share data between threads

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

What are race conditions and critical sections?

A

A race condition is where the result of an operation may not be deterministic, depending on which thread runs first. Critical sections are areas of code where these race conditions can cause significant problems, and we want to enable mutual exclusion.

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

What are atomicity violation bugs, and how can we solve them?

A

This is when instructions get interrupted halfway through a critical section, so that multiple threads modify it. It can be solved with locks.

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

What is an order violation bug, and how can we solve them?

A

This is when we intend for one thread to run before another, but they run out of order. We can fix this with conditional variables.

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

What is a deadlock? Why do they occur (4 reasons)

A

If one thread holds lock1, but also needs lock2, and another thread holds lock2, but also needs lock1, then neither thread will be able to run, and we have a deadlock.

They occur due to:

  • mutual exclusion
  • threads holding and waiting with locks
  • no preemption (so locks cannot be forcibly removed)
  • if we have circular waiting chains
How well did you know this?
1
Not at all
2
3
4
5
Perfectly