P3L4 Synchronization - Intro Flashcards

1
Q

Visual Metaphor

Synchonization is like __________________________________

  1. Repeatedly checking if can continue working
    • Sync using _____________
  2. Wait for a signal to continue working
    • Sync using __________ and ____________ variables
  3. Waiting hurts performance
    • Wasted _____ cycles
    • _______ effects
A

Synchonization is like … waiting for a co-worker to finish so you can continue working

  1. Repeatedly checking if can continue working
    • Sync using spinlocks
  2. Wait for a signal to continue working
    • Sync using mutexes and condition variables
  3. Waiting hurts performance
    • Wasted CPU cycles
    • Cache effects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is a spinlock different from a mutex?

A

When a spinlock is locked, and a thread is attempting to lock it, that thread is not blocked. Instead, the thread is spinning. It is running on the CPU and repeatedly checking to see if the lock has become free.

The thread will burn CPU cycles until the lock becomes free or until the thread is preempted for some reason. (e.g. timeslice up)

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

True or False?

If a semaphore is initialized with a counter of 1, it will behave like a mutex, only allowing one thread at a time to pass.

A

True - called a binary semaphore

sem_t m

sem_init(&m, 0, 1)

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

What are reader/writer locks good for?

A

to distinguish among different types of resource access.

For instance, we commonly want to distinguish “read” accesses - those that do not modify a shared resource - from “write” accesses - those that do modify a shared resource.

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

Why is it useful to have more powerful synchronization constructs, like reader-writer locks or monitors?

A

These constructs are more powerful because of their expressiveness.

Dealing with higher-level semantics that abstract away some of the lower-level components helps developers reduce the area for mistakes.

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

Name a bunch of synchronization constructs (11)

A
  1. mutex
  2. spinlock
  3. semaphore
  4. barrier
  5. condition variable
  6. read-write lock
  7. monitor
  8. serializers
  9. path-expressions
  10. rendez-vous points
  11. Optimistic wait point sync (RCU)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do all synchronization constructs have in common?

A

all need hardware support!

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