P2L2: Threads and Concurrency Flashcards

1
Q

What are benefits of multithreading?

A
  • parallelization => speed up - specialization => hot cache - efficiency => lower ram requirement 2 cheaper IPC Single CPU - If the the t_idle > 2*t_ctx_switch then it is useful to use more than 1 thread to avoid wasting too much time in the t_idle If the app is multithreaded and the OS is multithreaded that is helpful because threads can working for each app and OS services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Process vs. thread, describe the distinctions. What happens on a process vs. thread context switch.

A
  • Context switch time in thread is less than in process - Threads usually result in hotter caches when multiple exist compared to thread - Threads can share a virtual address space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When is it useful to add more threads, when does adding threads lead to pure overhead?

A

..

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

What are the possible sources of overhead associated with multithreading?

A

..

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

What are mutexes?

A
  • It is a construct with infor: locked, owner and blocked threads Functions - lock - unlock - Problem: Two thread manipulate and modify the same data resources at the same time and the result is unpredictable and sometimes wrong - Solution: Mutex uses a lock so that one thread does the work and modified the data resource exclusively. Only then the thread is done the other can continue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are condition variables?

A

wait(mutex, cond) signal(cond) Problem: - Having to loop continuously into lock, check the condition and if not unlock. Waste lock time

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

What are spurious wake-ups, how do you avoid them, and can you always avoid them?

A
  • Thread are awaken from waiting, but they can’t proceed because mutex is still locked. Therefore they are put in the mutex waiting queue - Doesn’t necessarily affect correctness, but affects performance - You can rewrite, put signal and broadcast out of lock if they do not depend on a condition related to the protected data resource and correctness no affected. Else, signal and broadcast need to be in lock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do you understand the need for using a while() look for the predicate check in the critical section entry code examples in the lessons?

A

If not used: - It is possible that when the signal is emitted the another thread affected the predicate condition. If not checked then the predicate condition logic could we not followed If used: - The predicate condition logic is always followed because we checked it again to verify it after the signal

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

What’s a simple way to prevent deadlocks? Why?

A
  • Two or more competing threads are waiting on each other to complete, but none of them ever do - prevent cycle in wait graph - Detection and recovery -Do nothing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the boss-worked multithreading pattern.

A
  • Boss assigns work to workers. Place work in a queue - Worker: performs entire tasks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you need to improve a performance metric like throughput or response time, what could you do in a boss-worker model? What are the limiting factors in improving performance with this pattern

A
  • Throughput = 1/ boss time per order - Reduce boss time per order - Queue synchronization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe the pipelined multithreading pattern.

A

+ specialization

  • balancing and synchronization overheads
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If you need to improve a performance metric like throughput or response time, what could you do in a pipelined model? What are the limiting factors in improving performance with this pattern?

A
  • Improve the weakest point in the pipeline by adding more threads
  • The limiting factors are maintaining pipeline balance, and additional synchronization operations, weakest point
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly