04 - Synchronisation Flashcards

1
Q

Mutual Exclusion

A

If a process is executing in its critical section, then no other processes can be executing in their critical sections

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

Critical Section

A

Segment of code where:
process may be changing common variables, updating table,
writing file, etc.

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

Critical-Section problem

A

Protocol that ensures safe access to shared resources by multiple threads or processes, preventing race conditions and ensuring data integrity during concurrent access to critical sections.

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

Progress

A

If no process is executing in its critical section and there are processes that want to enter their critical section, the selection of the process that will enter next can’t be postponed indefinitely

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

Bounded Waiting

A

A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section before that request is granted

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

Peterson’s Solution

A

Two Process Software Solution
Ensures mutual exclusion by providing a way for processes to take turns accessing a shared resource while preventing race conditions.
se of two shared variables, flags, and turn, along with careful synchronisation using atomic operations such as test-and-set or compare-and-swap.

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

Peterson variables

A

‘turn’
indicates whose turn it is

‘flag[i]’
indicates if process Pi is ready

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

Petersons Process Pi
‘flag[0] = true; turn =1;’

A

Enters critical section if Pj is not ready and turn is its own.

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

Petersons Process Pj
‘flag[1] = true; turn =0;’

A

Enters critical section if Pi is not ready and turn is its own.

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

Memory Barrier

A

Instruction ensuring changes in memory are visible to all processors

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

Memory Models

A

Guarantee memory behaviours in computer architectures

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

Strongly Ordered

A

Immediate visibility of memory modifications across processors

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

Weakly Ordered

A

Delayed visibility of memory modifications across processors

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

Memory Barrier Instruction

A

Ensures completion of loads and stores before subsequent operations

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

__sync_synchronize():

A

C function ensuring no memory operands move across the operation, backward or forward

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

Hardware Intructions

A

Special hardware instructions for testing and modifying data

17
Q

test_and_set

A

Atomically sets a boolean variable to true and returns its original value.

Example:
shared boolean lock = false

while test_and_set(&lock) == true:
print(“Thread 1 is printing”)
lock = false

18
Q

compare_and_swap

A

Atomically compares the value of a variable with an expected value and swaps it if they match.

Example:
shared integer counter = 0

new_value = counter + 1
compare_and_swap(&counter, counter, new_value)

19
Q

Atomic Variables

A

Variables providing uninterruptible updates on basic data types (integers and booleans)

20
Q

Increment()

A

Example: increment(&sequence) ensures uninterrupted incrementing of sequence.

Implementation: increment() function ensures atomic incrementing of an atomic integer variable.

21
Q

Mutex Locks

A

Software mechanism for controlling access to critical sections

Uses a boolean variable to indicate availability of the lock

Acquire lock before entering critical section, release afterward

22
Q

Semaphore

A

Synchronization primitive controlling access to shared resources

23
Q

wait(S)

A

Operation that decrements semaphore S;

if S <= 0, process blocks.

24
Q

signal(S)

A

Operation that increments semaphore S;

wakes up blocked process if any.

25
Q

Binary Semaphore

A

Semaphore with two states (0 or 1), typically used for mutual exclusion.

26
Q

Counting Semaphore

A

Semaphore with non-negative integer value, used for controlling access to multiple resources.

27
Q

Busy Waiting

A

A synchronization technique where a process repeatedly checks for a condition rather than blocking.

The process continuously executes a loop, checking the condition until it becomes true.

Often used in spinlocks and semaphore implementations.

28
Q

Dining Philsophers Problem:

N philosophers at a round table

Alternating between thinking and eating

Shared data: Bowl of rice, Semaphore chopstick[5] initialized to 1

A

Philosopher i:
wait(chopstick[i]);
wait(chopstick[(i + 1) % 5]);
eat for awhile
signal(chopstick[i]);
signal(chopstick[(i + 1) % 5]);
think for awhile

29
Q

Deadlock

A

A situation where two or more processes are unable to proceed because each is waiting for the other to release a resource.

30
Q

Hold and Wait

A

Processes hold resources while waiting for others, causing resource utilisation inefficiency

31
Q

Deadlock: Mutal Exclusion

A

Resources cannot be simultaneously shared, leading to exclusive access.

32
Q

No Preemption

A

Resources cannot be forcibly taken from a process; they must be released voluntarily.

33
Q

Circular Wait

A

A circular chain of processes exists, where each process holds a resource needed by the next process in the chain.

34
Q

Deadlock Example

A

Example: Two processes, P1 and P2, each holding one resource and waiting for the other resource held by the other process.
Requirements: Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait.

35
Q

Deadlock Prevention

A

Ensure at least one of the necessary conditions for deadlock does not hold. For example, using resource allocation strategies like deadlock avoidance or deadlock detection with resource allocation graphs.

36
Q

Banker’s Algorithm

A

Resource allocation algorithm to prevent deadlock and ensure safe resource usage.

Requirements:
Multiple resource instances, processes claiming maximum resource use a priori, and possible waiting for resource requests.

Data Structures:
-Available: Vector indicating available instances of each resource type.

-Max: Matrix specifying maximum resource needs for each process.

-Allocation: Matrix indicating currently allocated resources for each process.

-Need: Matrix representing remaining resource needs for each process.

Calculation:
Need[i,j] =
Max[i,j] - Allocation[i,j]