Threads + Synchronization Flashcards

1
Q

Difference between process & thread

A

Processes have separate virtual address spaces, threads share the same virtual address space

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

Which memory segment is not shared across threads

A

Stack memory - each thread gets its own stack

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

Data Race Problem

A

Multiple threads accessing and writing to the same memory at the same time, overwriting each others’ result

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

Non-deterministic outcome

A

The output of a non-deterministic program can be different each time it is run

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

Race Condition

A

A condition in which the correctness of a program depends on the timing/order of operations

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

Mutex lock

A

Mutual Exclusion lock - a primitive that allows only one thread to hold it

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

Blocking

A

A thread “waits” until the resource it is trying to access is free. We can’t control the order of threads that are waiting for the lock.

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

Atomicity

A

All code that is locked by a lock is atomic, i.e. all sub-operations would run as if they were a single operation, with no interference from other threads
“all or nothing” - runs all operations or none

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

Serialization

A

Using a lock serializes operations, only one thread can run operations guarded by a lock

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

Interleaving

A

Operations run from different threads are interleaved in some order, we can’t control the order in which different threads run

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

Thread safe function

A

A function that doesn’t access shared resources or provides proper protection for critical sections

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

Re-entrant function

A

Produces the correct output even when called again while being executed, therefore doesn’t use any shared variables

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

Deadlock

A

A set of threads hold a resource and wait to acquire a resource held by a different thread

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

Conditions for deadlock to occur

A
  1. Hold and wait - a thread is holding one resource and waiting for another
  2. Circular waiting - a set of threads is waiting for a resource held by the next thread
  3. Mutual exclusion
  4. No preemption - resource only released voluntarily by thread holding it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Livelock

A

A set of threads are still actively executing instructions but don’t make any progress

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

Producer-Consumer pattern

A

One set of threads is producing data, another set of threads is consuming data

17
Q

Condition variable primitive

A

Allows a thread to send a notification to the condition variable, and another thread can listen for updates from the condition variable

18
Q

pthread_cond_signal vs pthread_cond_broadcast

A

signal wakes up a single thread waiting on the condition, broadcast wakes up all threads waiting on it. broadcast should be used if waiting threads do different things

19
Q

Semaphore

A

A lock primitive with a “count” that allows multiple threads to grab the same lock

20
Q

Read-Write Lock

A

A lock that allows either unlimited readers or a single writer but not both (XOR)

21
Q

What primitive to use w/ Producer-Consumer w/ Bounded Buffer problem

A

Semaphore -