Synchronization Tools Flashcards

1
Q

Why do processes and threads cooperate with each other? (3 things)

A
  • information sharing
  • computation speed up
  • Modularity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Data can be shared with _____ ______ or _______ ________

A

shared memory, message passing

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

In shared memory, process A ____ shared memory, process B _____ this memory to their own _____ space and then is treated as ______ memory

A

creates, attaches, address, regular

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

In shared memory, ________ is needed to coordinate conflicting accesses

A

synchronization

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

POSIX APIs to shared memory synchronization include ______, _____ and ____

A

shm_open, shm_at, mmap

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

In message passing, process A sends message to B via _______

A

kernel

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

In message passing, processes can ____ for the message to be delivered

A

wait

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

The pros of shared memory is ______ and _______

A

speed, convenience

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

The cons of shared memory is having to ______ conflicts

A

manage

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

The pros of message passing is that there is no ______ and it is easy to _____ messages

A

conflict, exchange

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

The cons of message passing include high _______, ______ involvement, and the usage of several ______

A

overhead, kernel, syscalls

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

In the producer consumer problem, 2 _______ share a _______

A

threads, buffer

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

In the producer consumer problem, the producer places ______ into the buffer and must wait if it is ____

A

items, full

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

In the producer consumer problem, the consumer _____ items from the buffer and must wait if it is _____

A

takes, empty

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

In the producer consumer problem, we can coordinate producer and consumer by keeping a ______ on the # of items in the buffer

A

counter

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

In the producer consumer problem, how is count++ implemented?

A
register1 = count
register1 = register1 + 1
count = register1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In the producer consumer problem, how is count– implemented?

A
register2 = count
register2 = register2 -1
count = register2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

In the producer consumer problem, consumers and producers run on the ____ core or _______ cores in parallel

A

same, different

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

In the producer consumer problem, the CPU scheduler can switch between producer and consumer at ___ time

A

any

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

In the producer consumer problem, when can the counter start at 6, call count++, call count–, and end up at 7?

A

When the CPU decides to swap the process to the consumer and finish the consumer process before the producer finishes

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

What is a race condition?

A

When multiple processes manipulate shared data concurrently and the result depends on the order of manipulation

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

A ______ _____ is code that manipulates shared data

A

critical section

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

To handle race conditions, make sure that when one _______ is executing the __, no other processes can

A

process, CS

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

What 3 requirements must be satisfied for a solution the CS problem?

A
  • Mutual Exclusion
  • Progress
  • Bounded Waiting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Mutual Exclusion makes sure there is only ____ thread allows in the CS

A

one

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

Progress means that the thread should eventually _______

A

complete

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

Bounded Waiting means the process must wait for a _____ amount of time

A

finite

28
Q

On _____________ systems, the CS problem can be solved by disabling _________ and ________

A

uniprocessor, interrupts, preemption

29
Q

A problem on making a solution for the CS problem on a uniprocessor system is that users can make a ______ CS making the system _________

A

large, unresponsive

30
Q

Solutions for the CS problem on multicore systems can use ______ only or be supported with _______

A

software, hardware

31
Q

_______ solution is a software solution to the CS problem for only _____ processes

A

Peterson’s, two

32
Q

Peterson’s solution assumes ____ and ______- are atomic

A

load, store

33
Q

Peterson’s solution requires what 2 shared data items?

A
  • integer named turn

- Boolean array named flag[2]

34
Q

What does the turn value in peterson’s solution manage?

A

whose turn it is to enter CS

35
Q

What does the flag value in peterson’s solution manage?

A

hether the process/thread is ready to enter CS

36
Q

Describe Peterson’s solution in code

A
do { 
    flag[i] = true; 
    turn = j; 
    while (flag[j] && turn == j); 
      critical section 
    flag[i] = false; 
      remainder section 
} while (true);
37
Q

Does Peterson’s algorithm satisfy the 3 requirements?

A

yes

38
Q

Modern machines provide special _______ instructions that cannot be interrupted

A

atomic

39
Q

What does atomic swap do?

A

update the memory word with new value and return the old value

40
Q

What does Compare and swap do?

A

update one memory word if its original value matches a given value

41
Q

Describe a simple spinlock using atomic_swap

A
while(atomic_swap(&lock, 1)) {
    /* Do nothing */
}
  critical section
lock = 0;
  remainder section
42
Q

Describe a simple spinlock using compare and swap

A
while(compare_and_swap(&lock, 0, 1)) {
    /* Do nothing */
}
  critical section
lock = 0;
  remainder section
43
Q

Both simple spinlocks using atomic_swap and compare_and_swamp can cause _______ _______

A

indefinite waiting

44
Q

What are 2 software tools that are provided by libraries that can solve CS problems?

A

Mutex locks and semaphores

45
Q

_____ locks have an atomic acquire and release

A

Mutex

46
Q

Mutex/Spin locks can waste ____ _______, but prevents context switches

A

CPU cycles

47
Q

_______ _____ are widely used on multiprocessor systems

A

mutex locks

48
Q

A ________ is an integer variable accessed through two atomic operations: wait and signal

A

semaphore S

49
Q

What do semaphores do?

A

They control access to a finite number of instances of some resource

50
Q

In semaphores, wait ______ access to resources and signal _______ access

A

gains, releases

51
Q

In semaphores, S is initialized to the _____ of resource instances available

A

number

52
Q

In semaphores, S == 0 implies all _____ are being used

A

resources

53
Q

A binary semaphore is similar to a _____

A

mutex

54
Q

A _______ semaphore can be any integer value

A

counting

55
Q

What are the 3 use cases of semaphores?

A
  • Ensuring mutual exclusion
  • Synchronizing steps in different processes
  • Controlling access to finite resources
56
Q

A busy-waiting semaphore keeps _________ in the wait call and may waste ____ __________, but improves _______ time

A

spinning, CPU, cycles, response

57
Q

A non-busy-waiting semaphore ______ up the CPU when while waiting

A

frees

58
Q

A non-busy-waiting semaphore has an additional _____ ______ in its struct

A

wait list

59
Q

A non-busy-waiting semaphore has 2 internal operations: _____ and ________

A

block, wakeup

60
Q

A non-busy-waiting semaphore’s block operation _______ the process that invokes it, placing it in the ________ queue

A

suspends, waiting

61
Q

A non-busy-waiting semaphore’s wakeup operation _______ the execution of a ______ process, placing it in the _______ queue

A

resumes, blocked, ready

62
Q

In semaphores, _____ and ______ operations must become ______ _________

A

wait, signal, CS

63
Q

A non-busy-waiting semaphore does not completely remove busy waiting. why?

A

The busy waiting just got shifted from application-level CS entry to semaphore’s wait and signal commands, which are very short

64
Q

Why would we want to move busy waiting to the semaphore level rather than the user’s CS?

A

User application may run for a long time, busy waiting can be costly

65
Q

How can we use semaphores so that process 2 runs after process 1?

A
Semaphore synch (0);
Process 1
- Statement S1
- signal (synch)
Process 2
- wait(synch)
- Statement S2
66
Q

When can a dead lock occur using semaphores?

A

if P0 acquires S while P1 holds Q, P0 and P1 will wait for each other indefinitely