Synchronization Tools Flashcards

(66 cards)

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
Mutual Exclusion makes sure there is only ____ thread allows in the CS
one
26
Progress means that the thread should eventually _______
complete
27
Bounded Waiting means the process must wait for a _____ amount of time
finite
28
On _____________ systems, the CS problem can be solved by disabling _________ and ________
uniprocessor, interrupts, preemption
29
A problem on making a solution for the CS problem on a uniprocessor system is that users can make a ______ CS making the system _________
large, unresponsive
30
Solutions for the CS problem on multicore systems can use ______ only or be supported with _______
software, hardware
31
_______ solution is a software solution to the CS problem for only _____ processes
Peterson's, two
32
Peterson's solution assumes ____ and ______- are atomic
load, store
33
Peterson's solution requires what 2 shared data items?
- integer named turn | - Boolean array named flag[2]
34
What does the turn value in peterson's solution manage?
whose turn it is to enter CS
35
What does the flag value in peterson's solution manage?
hether the process/thread is ready to enter CS
36
Describe Peterson's solution in code
``` do { flag[i] = true; turn = j; while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true); ```
37
Does Peterson's algorithm satisfy the 3 requirements?
yes
38
Modern machines provide special _______ instructions that cannot be interrupted
atomic
39
What does atomic swap do?
update the memory word with new value and return the old value
40
What does Compare and swap do?
update one memory word if its original value matches a given value
41
Describe a simple spinlock using atomic_swap
``` while(atomic_swap(&lock, 1)) { /* Do nothing */ } critical section lock = 0; remainder section ```
42
Describe a simple spinlock using compare and swap
``` while(compare_and_swap(&lock, 0, 1)) { /* Do nothing */ } critical section lock = 0; remainder section ```
43
Both simple spinlocks using atomic_swap and compare_and_swamp can cause _______ _______
indefinite waiting
44
What are 2 software tools that are provided by libraries that can solve CS problems?
Mutex locks and semaphores
45
_____ locks have an atomic acquire and release
Mutex
46
Mutex/Spin locks can waste ____ _______, but prevents context switches
CPU cycles
47
_______ _____ are widely used on multiprocessor systems
mutex locks
48
A ________ is an integer variable accessed through two atomic operations: wait and signal
semaphore S
49
What do semaphores do?
They control access to a finite number of instances of some resource
50
In semaphores, wait ______ access to resources and signal _______ access
gains, releases
51
In semaphores, S is initialized to the _____ of resource instances available
number
52
In semaphores, S == 0 implies all _____ are being used
resources
53
A binary semaphore is similar to a _____
mutex
54
A _______ semaphore can be any integer value
counting
55
What are the 3 use cases of semaphores?
- Ensuring mutual exclusion - Synchronizing steps in different processes - Controlling access to finite resources
56
A busy-waiting semaphore keeps _________ in the wait call and may waste ____ __________, but improves _______ time
spinning, CPU, cycles, response
57
A non-busy-waiting semaphore ______ up the CPU when while waiting
frees
58
A non-busy-waiting semaphore has an additional _____ ______ in its struct
wait list
59
A non-busy-waiting semaphore has 2 internal operations: _____ and ________
block, wakeup
60
A non-busy-waiting semaphore's block operation _______ the process that invokes it, placing it in the ________ queue
suspends, waiting
61
A non-busy-waiting semaphore's wakeup operation _______ the execution of a ______ process, placing it in the _______ queue
resumes, blocked, ready
62
In semaphores, _____ and ______ operations must become ______ _________
wait, signal, CS
63
A non-busy-waiting semaphore does not completely remove busy waiting. why?
The busy waiting just got shifted from application-level CS entry to semaphore's wait and signal commands, which are very short
64
Why would we want to move busy waiting to the semaphore level rather than the user's CS?
User application may run for a long time, busy waiting can be costly
65
How can we use semaphores so that process 2 runs after process 1?
``` Semaphore synch (0); Process 1 - Statement S1 - signal (synch) Process 2 - wait(synch) - Statement S2 ```
66
When can a dead lock occur using semaphores?
if P0 acquires S while P1 holds Q, P0 and P1 will wait for each other indefinitely