slides08 - Synchronization Techniques (2) Flashcards

1
Q

Memory barriers

A
  • A compiler can reorder instructions for performance
  • A memory barrier is a hardware instruction (that tests and sets memory locations atomically/cannot be interrupted) to ensure an order of memory operations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Memory models (2)

A
  1. Strongly ordered: memory modification on one processor immediately visible to all other processors
  2. Weakly ordered: memory modifications in one processor not immediately visible to all other processors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Test_and_set (TAS)

A

Retrieve current value of a memory and set it to 1 in an uninterruptable instruction

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

Compare_and_swap (CAS)

A
  • Sets the memory variable to the new value only if the current value is same as expected (atomic operation)
  • Returns old value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Atomic variables

A
  • Variable that can be accessed and modified atomically
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Semaphore

A
  • Two operations: wait(s) and signal(s)
  • Initial value set to any non negative integer
  • The initial value determines how many threads can access that variable at once - otherwise they have to wait
  • To implement a CS: set semaphore value to 1 so only one process can be in the CS at any given time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Monitor

A
  • Similar to a “class” provided by object-oriented languages
  • Provides a CS for free -> no need to mutexes/locks
  • Define functions inside Monitor x and call like x.func() -> call once to enter CS and when function terminates, exit CS
  • No two functions in Monitor x can be executed at the same time
  • Monitor provides facilities for threads to sleep inside the monitor - these threads are not active in the monitor
  • Condition variables:
    cond var -> can call var.cwait() and var.csignal()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Barrier synchronization

A
  • When multiple processes/threads get to a barrier point -> must wait for all to arrive and then execute at the same time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly