18+19 Flashcards

1
Q

What is the data race problem? What is a critical section?

A

This can occur when multiple processes/threads are accessing the same data/memory location and at least one of them is modifying the data. This can lead to the data being modified before it is supposed to. To prevent this certain parts of the cooperating processes are not interleaved(interrupted). The critical section is the special protected sections.

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

What are the critical section requirements?

A
Mutual exclusion(only one process executing critical section at a time).
Bounded waiting(When a process becomes ready to enter its critical section, there must be a bound on how many times other processes can enter their critical sections 
Progress(no process executing a non-critical section can stop a process from entering its critical section, and the decision to enter a critical section cannot be indefinitely postponed.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Peterson’s algorithm?

A

Have a flag and a turn, for a process to enter its critical section its flag must be set to true and the turn must be its turn.

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

What does synchronisation hardware do?

A

provide special atomic instructions which cannot be interrupted.

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

What is the CAS function?

A

An atomic instruction CAS(o, a, n) checks if the value at address a is o, write the value n to address a and return true, otherwise return false. It can be used to implement locking systems.

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

How does test and set work?

A

Begin with a variable called lock, set to false. Now have a while loop that checks to see if it is set to false. If it is, set the lock and do critical section. If not, wait till it is. Don’t forget to unset the lock when done.

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

What is a semaphore?

A

An integer variable that can only be accessed via two atomic instructions, Wait(S): wait while S is less than or equal to 0. Decrease S by 1 Signal(S): increase S by 1.
They are commonly used in synchronisation.

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

How can we reduce busy waiting for a semaphore?

A

Use a process queue.

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

What are common semaphore values?

A

1 for mutex, 0 for process synchronization, > 1 for concurrent processes/threads. Note that semaphores can get negative values, in which case it tells us how many processes are waiting.

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

What is a monitor? What is it in java?

A

A high level language construct to make synchronisation easier for programmers. In java the synchronized keyword is used, this is done using a lock.

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

What is a deadlock and how can it be fixed?

A

This can occur when a process with control of the lock can’t do what is required, locking out other processes while getting nothing done. This can be fixed using wait and notify. Wait lets a thread go into wait set and unlocks the lock, notify causes an arbitrary thread to be picked from the object’s wait list.

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

What does a deadlock require?

A

This occurs when every process is waiting for an event that can only be caused by another process in the set. They require mutual exclusion, at least one process to hold a resource and one waiting, no preemption(resource can only be released by process holding it), and circular wait(waiting in circular fashion).

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

What is a resource allocation graph? How can this be used to detect deadlocks?

A

Graph containing: process nodes , resource nodes. Request edges connect a process to a resource, an assignment edge represents a resource has been given to a process. When a request is granted the request edge is transformed ot an assignment edge. When a resource is released the assignment edge is deleted.
If the graph contains no cycles the system is not deadlocked, if the graph contains a cycle with only one instance of each resource involved the system is deadlocked, otherwise it might be.

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

How can we prevent deadlocks?

A
Stop one of: mutual exclusion( not feasible in most cases)
Hold and wait(force process to be given all resources before starting execution, or can only request resources when has none, bas utilisation and starvation).
No preemption(allow processes to preempt resources held by other processess, requires saveable state).
Circular wait(impose total ordering of all resource types).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a safe state?

A

A system is in a safe state if there is a process sequence so that each process gets all the resources it wants, using only the resources currently free and the collection of resources requested by all processes before it. We can be safe if we execute the processes in this sequence.

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

What is an algorithm for deadlock avoidance?

A

for environment where there is only one instance of each resource type:
Add claim edge to resource allocation graph, this indicates a process may request the resource in the future. If this would lead to an unsafe state don’t allow this to upgrade to an assignment edge.

17
Q

When might we want to check for deadlocks? What can we do to fix it?

A

Whenever CPU utilisation falls below some threshold. We could then either abort all deadlocked processes, abort one at a time, preempt resources one at a time or restart affected processes