L8 & L9 Flashcards

1
Q

What is a barrier? What is a lock? What are both used for?

A

A barrier is where a number of threads have to reach to proceed.

Locks protect shared data from concurrent access.

Synchronisation

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

What is a use application of a barrier?

A

when data dependencies limit loop parallelisation

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

What is a way locks can be used?

A

To deal with race conditions by serialising access to shared data. This ensures that critical sections are executed atomically.

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

What are critical sections of a program?

A

Where shared data is accessed or updated

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

How do locks limit the execution of a critical section?

A

Serialisation: amount of threads that can concurrently execute it (generally 1)

Atomicity: when a thread A starts to run a critical section S, T must finish S before another thread can run S.

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

How are condition variables used in mutexes?

A

Condition variables are used to signal threads waiting for a lock to be free and an arbitrary event. Thread wakes up right when needed without spinning (busy wait).

pthread_cond_wait
pthread_cond_signal

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

What is the difference between coarse-grained locking and fine-grained locking? What is a disadvantage of each?

A

Coarse-grained locking involves using a single lock to protect shared data. Fine-grained locking involves using a seperate lock for each data access.

Coarse-grained locking limits parallelism. Fine-grained locking may lead to increased overhead.

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

What is a reentrant lock used for?

A

It allows a lock to be taken by a thread that already holds it without deadlocking.

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

What are 4 lock types?

A

Mutex
Reentrant lock
Semaphores
Spinlocks
Read-write locks

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

______ are mutexes that can be held by multiple threads.

A

Semaphores

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

In a _______, threads will be busy-wait if the lock is unavailable.

A

Spinlock

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